PHPackages                             dottedai/laravel-query-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dottedai/laravel-query-logger

ActiveLibrary

dottedai/laravel-query-logger
=============================

A package to log and display database queries like Rails console.

02.1k↓38.9%PHP

Since Mar 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dotted-ai/laravel-query-logger)[ Packagist](https://packagist.org/packages/dottedai/laravel-query-logger)[ RSS](/packages/dottedai-laravel-query-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Query Logger
====================

[](#laravel-query-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4f99336d1b81517247bdbc8ca263c27da5bdba15284def6dafd39e882503bc17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f7474656461692f6c61726176656c2d71756572792d6c6f676765722e737667)](https://packagist.org/packages/dottedai/laravel-query-logger)[![License](https://camo.githubusercontent.com/14bca20fbf0c87cbbe856e4b5fdf2af92c6bb1c8df2b42bb0bec706391b95ea0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646f7474656461692f6c61726176656c2d71756572792d6c6f676765722e737667)](https://packagist.org/packages/dottedai/laravel-query-logger)

A simple Laravel package to log and display database queries similar to Rails' console output. This tool is intended for use in local development environments, making it easier to debug and optimize your SQL queries.

Features
--------

[](#features)

- **Automatic Query Logging:** Listens to all database queries executed by your Laravel application.
- **Log File Integration:** Records each query, including execution time, into Laravel's default log file (`storage/logs/laravel.log`).
- **Browser Console Output:** Optionally outputs queries to the browser's JavaScript console for quick inspection.
- **Route Logging:** Logs route details—including the URI, controller, and middleware—to provide a complete view of the request lifecycle.
- **Console Info Logging:** Displays `Log::info` (and higher level) messages in the terminal (when using `php artisan serve`) by adding a custom Monolog handler.
- **Development Focused:** Designed to work in the local environment to aid debugging without impacting production performance.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- Laravel 6.x, 7.x, 8.x, 9.x, or 10.x

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require dottedai/laravel-query-logger
```

Laravel's package auto-discovery will automatically register the service provider. If you need to manually register it, add the following to your `config/app.php` file within the providers array:

```
Dottedai\QueryLogger\QueryLoggerServiceProvider::class,
```

Usage
-----

[](#usage)

Once installed and registered, the package will automatically begin listening for database queries, route events, and log messages when your application is running in the local environment.

How It Works
------------

[](#how-it-works)

### Query Listener

[](#query-listener)

The package uses Laravel's `DB::listen` method to capture all SQL queries, replaces query placeholders with their actual binding values, and logs the query along with its execution time.

### Route Logging

[](#route-logging)

It listens for Laravel's `RouteMatched` event to log route details such as the URI, controller handling the request, and any associated middleware.

### Console Output

[](#console-output)

When using the built-in PHP server (`php artisan serve`), queries and route logs are output to the terminal using PHP's `error_log()` function.

### Console Info Logging

[](#console-info-logging)

A custom Monolog handler is added to also output `Log::info` (and higher-level) messages to the terminal. This means that any log calls such as `Log::info`, `Log::warning`, or `Log::error` will appear in your console when running locally.

Example Output
--------------

[](#example-output)

When a query is executed and a route is matched, you might see output similar to this in your log file and terminal:

```
Query: SELECT * FROM users WHERE email = 'example@example.com' [12 ms]
Route: api/users | Controller: App\Http\Controllers\UserController@index | Middleware: api, auth
INFO: Application started successfully.

```

Customization
-------------

[](#customization)

You can modify the behavior of the query logger by editing the `QueryLoggerServiceProvider` class. For example, you might choose to disable the JavaScript console output, adjust the logging level, or customize the route logging format to fit your needs.

Important Considerations
------------------------

[](#important-considerations)

### Development Use Only

[](#development-use-only)

This package is meant for local development environments. Ensure it is disabled or removed from production to prevent potential performance issues or the inadvertent exposure of sensitive query data.

### Security

[](#security)

Logging SQL queries and other sensitive application data can expose critical information. Always use this tool only in safe, non-production environments.

Contributing
------------

[](#contributing)

Contributions, suggestions, and bug reports are welcome! Feel free to submit an issue or pull request on GitHub.

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/daf3ae1a09d0082449e5018d6e3ac1db411340b39c38ff9015dfaf3b76b46b8d?d=identicon)[puppe1990](/maintainers/puppe1990)

---

Top Contributors

[![puppe1990](https://avatars.githubusercontent.com/u/8432835?v=4)](https://github.com/puppe1990 "puppe1990 (10 commits)")

### Embed Badge

![Health badge](/badges/dottedai-laravel-query-logger/health.svg)

```
[![Health](https://phpackages.com/badges/dottedai-laravel-query-logger/health.svg)](https://phpackages.com/packages/dottedai-laravel-query-logger)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
