Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
/ laravel-query-log Public archive

Log database queries to an output channel of your choice

License

Notifications You must be signed in to change notification settings

mll-lab/laravel-query-log

Repository files navigation

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

About

Log database queries to an output channel of your choice

Resources

License

Stars

Watchers

Forks

Packages

No packages published