PHP code example of mitoop / laravel-query-logger

1. Go to this page and download the library: Download mitoop/laravel-query-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mitoop / laravel-query-logger example snippets




return [
    'channels' => [
        // 其他日志频道配置...
        'sql' => [
            'driver' => 'daily',
            'path' => storage_path('logs/sql.log'),
            'level' => env('LOG_LEVEL', 'debug'),
            'permission' => 0664,
        ],
    ],

    // 查询日志相关配置
    'query' => [
        'enabled' => env('ENABLE_QUERY_LOG', false), // 总开关,是否启用 SQL 查询日志
        'channel' => 'sql', // 日志记录频道
        'excluded_tables' => ['telescope_'], // 排除表名,支持前缀匹配
    ],
];


use Mitoop\LaravelQueryLogger\SqlDebug;

public function boot()
{
    SqlDebug::enableWhen(function () {
        return is_local() || is_dev() || request()->hasCookie('debug_sql');
    });
}