monolog库里面的handle有个变量$bubble设置,表示在这个handle处理结束后是否需要下一个handle处理,“Handlers also have a $bubble property which defines whether they block the record or not if they handled it”,所以上面的代码在构造handle时将第三个参数设置为false(默认值为true);
很多时候我们可能希望debug/info/notice放在一个文件,warning之后的放在另一个文件,那么可以这么设置
$app->configureMonologUsing(function($monolog) {
$handlers = [
(new Monolog\Handler\StreamHandler(storage_path().'/logs/laravel_warning.log', Monolog\Logger::WARNING,false))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true)),
(new Monolog\Handler\StreamHandler(storage_path().'/logs/laravel.log', Monolog\Logger::DEBUG,false))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true)),
];
$monolog->setHandlers($handlers);
});
这里warning一定要放在info之前,因为在monolog中找第一个符合条件的handle函数如下:
public function isHandling(array $record)
{
return $record['level'] >= $this->level;
}