Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Laravel中创建和使用自定义每日日志文件?_Php_Laravel_Logging - Fatal编程技术网

Php 如何在Laravel中创建和使用自定义每日日志文件?

Php 如何在Laravel中创建和使用自定义每日日志文件?,php,laravel,logging,Php,Laravel,Logging,在Laravel中,我在/config/logger.php中定义了一个自定义日志文件: 'mycustomlog' => [ 'driver' => 'stack', 'path' => storage_path('logs/mycustomlog.log'), 'level' => 'info', ], 以下是我的上下文堆栈驱动程序: 'stack' => [ 'driver' => 'stack', 'channels' =>

在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' => [
   'driver' => 'daily',
   'channels' => ['syslog'],
   'path' => storage_path('logs/mycustomlog.log'),
   'level' => 'info',
],
创建(每日)日志文件并记录异常。即
mycustomlog-2019-11-07.log

实际发生的情况:

'mycustomlog' => [
   'driver' => 'daily',
   'channels' => ['syslog'],
   'path' => storage_path('logs/mycustomlog.log'),
   'level' => 'info',
],
未创建日志文件,但以下错误记录到
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',
],

您需要在config
logger.php中有通道,请参见。堆栈驱动程序的要点是向多个通道报告

'mycustomlog' => [
    'driver' => 'stack',
    'channels' => ['daily'],
    'path' => storage_path('logs/mycustomlog.log'),
    'level' => 'info',
],

如果您不希望它在堆栈中,您可以让您的配置像这样指向单个驱动程序

'mycustomlog' => [
  'driver' => 'single',
  'path' => storage_path('logs/mycustomlog.log'),
  'level' => 'info',
]
然后用你自己试过的方法来称呼它

Log::channel('mycustomlog')->info($e);

也许你不想要“stack”驱动程序,而想要“daily”驱动程序?@lagbox注意,我选择“stack”的原因是因为我需要“daily”驱动程序和“syslog”驱动程序。你说你想要使用
stack
驱动程序并不意味着它正在使用你定义的
stack
通道。。。这是一个名为“stack”的通道,碰巧使用了“stack”drivernice catch@lagbox。我已经添加了通道,但仍然没有创建自定义日志文件。请参阅下面mrhn回答中的我的评论。请记住,
每日
驱动程序在
天数
键下设置的天数之后删除日志。要永久保留它们,只需将其设置为
0
。我将“通道”添加到配置中,现在我不再收到错误,但不会创建mycustomlog-2019-11-07.log,而是将我的错误记录到laravel-2019-11-07.log。这是因为我指定了“daily”频道吗?是的,因为名为“daily”的频道配置为以这种方式工作。。。您需要创建自己的频道,使用“每日”驱动程序并进行配置that@lagbox太好了,谢谢。我将用解决方案更新我的问题。有人能回答这个问题吗