1.修改 config/logging.php
channels数组的 single、daily、slack 加 ‘permission’ => 0666, 即日志文件的权限。
2. .env文件
LOG_CHANNEL = daily
LOG_LEVEL = debug
如果需要记录sql日志:
1.config/logging.php的channels数组中加
'sql' => [
'driver' => env('LOG_CHANNEL', 'stack'),
'path' => storage_path('logs/sql.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
'permission' => 0666,
],
2 修改app/Providers/AppServiceProvider.php
public function register()
{
//sql 日志记录
if (env('APP_DEBUG', false)) {
DB::listen(function ($query) {
$tmp = str_replace('?', '"' . '%s' . '"', $query->sql);
if ($query->bindings) {
$tmp = vsprintf($tmp, $query->bindings);
}
$tmp = str_replace('\\', '', $tmp);
Log::channel('sql')->info($tmp);
});
}
}