在 Laravel 中,我在 /config/logger.php
中定义了一个自定义日志文件:
'mycustomlog' => [
'driver' => 'stack',
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
这是我的上下文堆栈驱动程序:
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'syslog'],
'ignore_exceptions' => false,
],
我是这样称呼它的:
Log::channel('mycustomlog')->info($e);
我期望发生的事情:
创建(每日)日志文件并记录异常。即
mycustomlog-2019-11-07.log
实际发生的情况:
没有创建日志文件,但以下错误被记录到
laravel.log
:[2019-11-07 10:25:31] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (ErrorException(code: 0): Undefined index: channels at /var/www/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:232)
解决方案:
'mycustomlog' => [
'driver' => 'daily',
'channels' => ['syslog'],
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
最佳答案
您将需要在配置中包含 channel logger.php
见 here .堆栈驱动程序的重点是向多个 channel 报告。
'mycustomlog' => [
'driver' => 'stack',
'channels' => ['daily'],
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
关于php - 如何在 Laravel 中创建和使用自定义的每日日志文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58746816/