PHPackages                             andriichuk/laravel-db-query-sniffer - 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. [Database &amp; ORM](/categories/database)
4. /
5. andriichuk/laravel-db-query-sniffer

ActiveLibrary[Database &amp; ORM](/categories/database)

andriichuk/laravel-db-query-sniffer
===================================

Laravel package to log SQL queries and Redis commands with raw SQL, binary-safe bindings, and slow-query filters

0.1.2(yesterday)01↑2900%MITPHP ^8.3

Since Jul 22Compare

[ Source](https://github.com/andriichuk/laravel-db-query-sniffer)[ Packagist](https://packagist.org/packages/andriichuk/laravel-db-query-sniffer)[ Docs](https://github.com/andriichuk/laravel-db-query-sniffer)[ RSS](/packages/andriichuk-laravel-db-query-sniffer/feed)WikiDiscussions Synced today

READMEChangelog (3)Dependencies (14)Versions (4)Used By (0)

Laravel DB Query Sniffer
========================

[](#laravel-db-query-sniffer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/404afcf6970dea02f7da0e9bca73a949454b6df533de1bc05662dfc74a0dc2dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647269696368756b2f6c61726176656c2d64622d71756572792d736e69666665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andriichuk/laravel-db-query-sniffer)[![GitHub Tests Action Status](https://camo.githubusercontent.com/1dad2d9c762d137d32414e52789219da3a0b7e281f409c3c0fd656c4729355ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647269696368756b2f6c61726176656c2d64622d71756572792d736e69666665722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/andriichuk/laravel-db-query-sniffer/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/7867a554b1be5c62ada1ec0f756eb8ff114da53308d5a748bcbfd8938d00e8b9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647269696368756b2f6c61726176656c2d64622d71756572792d736e69666665722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/andriichuk/laravel-db-query-sniffer/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/4700e746967647ad0c47dd324e263ca088eac8e0c149342ce7054dbab06dfcfa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647269696368756b2f6c61726176656c2d64622d71756572792d736e69666665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andriichuk/laravel-db-query-sniffer)

Log **SQL queries** and **Redis commands** in Laravel during local development — with raw SQL, binary-safe binding fallbacks, and optional slow-query filters.

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

[](#requirements)

- PHP **8.3+**
- Laravel **11.x**, **12.x**, or **13.x**

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

[](#installation)

```
composer require andriichuk/laravel-db-query-sniffer --dev
```

Publish the config (optional):

```
php artisan vendor:publish --tag="db-query-sniffer-config"
```

Add dedicated log channels in `config/logging.php` (recommended):

```
'channels' => [
    // ...
    'db' => [
        'driver' => 'daily',
        'path' => storage_path('logs/db.log'),
        'level' => 'debug',
        'days' => 2,
    ],
    'redis' => [
        'driver' => 'daily',
        'path' => storage_path('logs/redis.log'),
        'level' => 'debug',
        'days' => 2,
    ],
],
```

> **When is logging on?** If `LOG_DB_QUERIES` is not set, the sniffer follows **`APP_DEBUG`**. Set `LOG_DB_QUERIES=true` or `false` to force it. Override channels with `DB_QUERY_LOG_CHANNEL` and `REDIS_COMMAND_LOG_CHANNEL`.

Configuration
-------------

[](#configuration)

KeyDescriptionDefault`enabled`Master switch`env('LOG_DB_QUERIES', APP_DEBUG)``environments`Environments where listeners are registered (`['*']` = all)`['local']``database.enabled`Log SQL queries`true``database.channel`Log channel for SQL`db``database.slow_only`When true, only log queries ≥ `slow_ms``false``database.slow_ms`Minimum query duration (ms) when `slow_only` is enabled`100``database.include_connection`Include connection name in context`true``redis.enabled`Log Redis commands`true``redis.channel`Log channel for Redis`redis``redis.slow_only`When true, only log commands ≥ `slow_ms``false``redis.slow_ms`Minimum command duration (ms) when `slow_only` is enabled`100``bindings.max_string_length`Truncate string bindings (`null` = no limit)`null``bindings.binary_as_base64`Include base64 for binary bindings`true`Example log output
------------------

[](#example-log-output)

```
[2026-07-22 06:50:01] local.INFO: SQL Query: {"query":"select * from `users` where `id` = 1","time":"1.24ms","connection":"mysql"}
[2026-07-22 06:50:01] local.INFO: Redis Command: {"command":"GET","parameters":["user:1"],"time":"0.31ms","connection":"default"}

```

When `toRawSql()` fails (e.g. binary bindings), a warning is logged with sanitized bindings instead of crashing:

```
[2026-07-22 06:50:02] local.WARNING: Failed to build raw SQL query string. Logging fallback payload. {"error":"...","sql":"select ?","bindings":["[binary:16 bytes;base64=...]"],"time":"0.5ms","connection":"mysql"}

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1d ago

### Community

Maintainers

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

---

Tags

laravelloggingdebugdatabasesqlredisquerydevelopmentloggersnifferquery log

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/andriichuk-laravel-db-query-sniffer/health.svg)

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

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M656](/packages/spatie-laravel-medialibrary)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592456.3k2](/packages/spiritix-lada-cache)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.6k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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