【发布时间】:2020-03-03 22:06:09
【问题描述】:
在 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',
],
【问题讨论】:
-
也许您不想要“堆栈”驱动程序而是“日常”驱动程序?
-
@lagbox 注意我选择“stack”的原因是因为我需要“daily”驱动程序和“syslog”驱动程序
-
您说要使用
stack驱动程序并不意味着它正在使用您定义的stack通道......这是一个名为“stack”的通道,恰好使用“堆栈”驱动程序 -
nice catch @lagbox 我已经添加了频道,但仍未创建自定义日志文件。在下面的 mrhn 的回答中查看我的评论。
-
请记住,
daily驱动程序会在days键下设置的天数之后删除日志。要永久保留它们,只需将其设置为0。