mll-lab/laravel-query-log

将数据库查询记录到您选择的输出通道

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

This package is auto-updated.

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


README

您可以通过在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

将数据库查询记录到您选择的输出通道。

codecov GitHub license

Packagist Packagist

安装

composer require mll-lab/laravel-query-log

就这样。Laravel的包发现机制将自动启动。

配置

默认情况下,所有数据库查询都写入到storage/logs/query.log。如果您想更改位置,请发布配置文件。

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