mll-lab/laravel-query-log

This package is abandoned and no longer maintained. The author suggests using the See https://github.com/mll-lab/laravel-query-log README for a recipe to replace this package instead.

Log database queries to an output channel of your choice

v2.3.0 2022-05-16 08:35 UTC

This package is auto-updated.

Last update: 2024-04-23 08:17:55 UTC


README

You can easily implement what this package does by adding something like this to DatabaseServerProvider::boot():

if (env('APP_DEBUG')) {
    DB::listen(function (QueryExecuted $query): void {
        $sql = str_replace("\n", ' ', $query->sql);
        $bindings = \Safe\json_encode($query->bindings);

        \Safe\file_put_contents(
            filename: storage_path('logs/query.log'),
            data: "SQL: {$sql} ||| Bindings: {$bindings} ||| Time: {$query->time}ms\n",
            flags: FILE_APPEND,
        );
    });
}

laravel-query-log

Log database queries to an output channel of your choice.

codecov GitHub license

Packagist Packagist

Installation

composer require mll-lab/laravel-query-log

That's it. Laravel's package discovery will automatically kick in.

Configuration

All database queries are written to storage/logs/query.log by default. If you want to change the location, publish the configuration file:

php artisan vendor:publish --tag=query-log-config