PHPackages                             mnabialek/laravel-sql-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. [Database &amp; ORM](/categories/database)
4. /
5. mnabialek/laravel-sql-logger

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

mnabialek/laravel-sql-logger
============================

Log SQL queries in Laravel/Lumen framework

v2.2.12(4mo ago)158796.3k↓12.4%28[1 issues](https://github.com/mnabialek/laravel-sql-logger/issues)[5 PRs](https://github.com/mnabialek/laravel-sql-logger/pulls)2MITPHPPHP ^7.0|^8.0CI passing

Since Feb 16Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/mnabialek/laravel-sql-logger)[ Packagist](https://packagist.org/packages/mnabialek/laravel-sql-logger)[ RSS](/packages/mnabialek-laravel-sql-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (28)Used By (2)

Laravel SQL Logger
------------------

[](#laravel-sql-logger)

[![Packagist](https://camo.githubusercontent.com/154fe4312670e8cde256f74de7a4c4f751cedcd93f9ca95e69e508f6cba9bb78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6e616269616c656b2f6c61726176656c2d73716c2d6c6f676765722e737667)](https://packagist.org/packages/mnabialek/laravel-sql-logger)[![Tests](https://github.com/mnabialek/laravel-sql-logger/workflows/Tests/badge.svg)](https://github.com/mnabialek/laravel-sql-logger/actions)[![codecov](https://camo.githubusercontent.com/7bdbf7dab01aa2224a1b91c8736a4f7d15ecef8dbb8ed4278857b6165d2ab94e/68747470733a2f2f636f6465636f762e696f2f67682f6d6e616269616c656b2f6c61726176656c2d73716c2d6c6f676765722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mnabialek/laravel-sql-logger)

This module allows you to log SQL queries (and slow SQL queries) to log file in Laravel/Lumen framework. It's useful mainly when developing your application to verify whether your queries are valid and to make sure your application doesn't run too many or too slow database queries.

### Requirements

[](#requirements)

- Laravel 5.8 - 12.x
- Lumen 5.8 - 11.x (Lumen development discontinued after version 11)
- PHP 7.4 - 8.5

### Installation

[](#installation)

1. Run

    ```
    composer require mnabialek/laravel-sql-logger --dev
    ```

    in console to install this module (Notice `--dev` flag - it's recommended to use this package only for development).
2. If you use Laravel &lt; 5.5 open `config/app.php` and in `providers` section add:

    ```
    Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class,
    ```

    Laravel 5.5 uses Package Auto-Discovery and it will automatically load this service provider so you don't need to add anything into above file.

    If you are using Lumen open `bootstrap/app.php` and add:

    ```
    $app->register(Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class);
    ```
3. If you use Laravel &lt; 5.5 run:

    ```
    php artisan vendor:publish --provider="Mnabialek\LaravelSqlLogger\Providers\ServiceProvider"
    ```

    in your console to publish default configuration files.

    If you are using Laravel 5.5 run:

    ```
    php artisan vendor:publish
    ```

    and choose the number matching `"Mnabialek\LaravelSqlLogger\Providers\ServiceProvider"` provider.

    By default you should not edit published file because all the settings are loaded from `.env` file by default.

    For Lumen you should skip this step.
4. In your .env file add the following entries:

    ```
    SQL_LOGGER_DIRECTORY="logs/sql"
    SQL_LOGGER_USE_SECONDS=false
    SQL_LOGGER_CONSOLE_SUFFIX=
    SQL_LOGGER_LOG_EXTENSION=".sql"
    SQL_LOGGER_ALL_QUERIES_ENABLED=true
    SQL_LOGGER_ALL_QUERIES_OVERRIDE=false
    SQL_LOGGER_ALL_QUERIES_PATTERN="#.*#i"
    SQL_LOGGER_ALL_QUERIES_FILE_NAME="[Y-m-d]-log"
    SQL_LOGGER_SLOW_QUERIES_ENABLED=true
    SQL_LOGGER_SLOW_QUERIES_MIN_EXEC_TIME=100
    SQL_LOGGER_SLOW_QUERIES_PATTERN="#.*#i"
    SQL_LOGGER_SLOW_QUERIES_FILE_NAME="[Y-m-d]-slow-log"
    SQL_LOGGER_FORMAT_NEW_LINES_TO_SPACES=false
    SQL_LOGGER_FORMAT_ENTRY_FORMAT="/* [origin]\\n   Query [query_nr] - [datetime] [[query_time]] */\\n[query]\\n[separator]\\n"

    ```

    and adjust values to your needs. You can skip variables for which you want to use default values.

    If you have also `.env.sample` it's also recommended to add those entries also in `.env.sample` file just to make sure everyone know about those env variables. Be aware that `SQL_LOGGER_DIRECTORY` is directory inside storage directory. If you want you can change it editing `config/sql_logger.php` file.

    To find out more about those setting please take a look at [Configuration file](publish/config/sql_logger.php)
5. Make sure directory specified in `.env` file exists in storage path and you have valid file permissions to create and modify files in this directory (If it does not exist this package will automatically create it when needed but it's recommended to create it manually with valid file permissions)
6. Make sure on live server you will set logging SQL queries to false in your `.env` file. This package is recommended to be used only for development to not impact production application performance.

### Upgrading from 1.\*

[](#upgrading-from-1)

When upgrading from `1.*` version you should remove current `sql_logger.php` config file and replace this with new one (see installation step). You should also use new variables in `.env` file (old won't be used).

### Authors

[](#authors)

Author of this awesome package is **[Marcin Nabiałek](http://marcin.nabialek.org/en/)** and [Contributors](https://github.com/mnabialek/laravel-sql-logger/graphs/contributors)

### Changes

[](#changes)

All changes are listed in [Changelog](CHANGELOG.md)

### License

[](#license)

This package is licenced under the [MIT license](LICENSE) however [Support](#support) is more than welcome.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance73

Regular maintenance activity

Popularity55

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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.

###  Release Activity

Cadence

Every ~149 days

Recently: every ~454 days

Total

25

Last Release

148d ago

Major Versions

1.0.x-dev → v2.02018-02-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e68c5eb4daa861595caa21f3d4c6f94ff25118535bc8eac93648b095eab307?d=identicon)[mnabialek](/maintainers/mnabialek)

---

Top Contributors

[![mnabialek](https://avatars.githubusercontent.com/u/7656807?v=4)](https://github.com/mnabialek "mnabialek (112 commits)")[![yhbyun](https://avatars.githubusercontent.com/u/946080?v=4)](https://github.com/yhbyun "yhbyun (1 commits)")

---

Tags

loglaravellumensqlloggersql logsql loggerlog sql querieslog sql

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mnabialek-laravel-sql-logger/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[altek/accountant

The auditing &amp; accountability package for Laravel's Eloquent ORM.

92954.3k4](/packages/altek-accountant)[klaravel/db-logger

Laravel database/sql queries logger.

132.4k](/packages/klaravel-db-logger)

PHPackages © 2026

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