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_'] // 排除表,支持表名前缀匹配
    ]
];

public function boot()
{
     // 设置自定义触发条件
     Condition::using(function () {
         return is_local() || is_dev() || request()->hasCookie('debug_sql');
     });
}