我使用webman并开启协程(Workerman\Events\Swoole::class),我现在模拟并发请求100次test,按正常来说,我的log2日志文件应该有100次【请求进来】的日志,但我发现记录一部分后会提示log2.WARNING: A possible infinite logging loop was detected and aborted. It appears some of your handler code is triggering logging, see the previous log record for a hint as to what may be the cause. [] [],请问为何呢
<?php
namespace app\controller;
use support\Request;
use support\Log;
class IndexController
{
public function test(Request $request){
$log = Log::channel('log2');
sleep(3);
$log->info('请求进来');
return json(array('ok2'));
}
}
#config下的log配置
return [
// log2通道
'log2' => [
// 处理默认通道的handler,可以设置多个
'handlers' => [
[
// handler类的名字
'class' => Monolog\Handler\RotatingFileHandler::class,
// handler类的构造函数参数
'constructor' => [
runtime_path() . '/logs/log2.log',
Monolog\Logger::DEBUG,
],
// 格式相关
'formatter' => [
// 格式化处理类的名字
'class' => Monolog\Formatter\LineFormatter::class,
// 格式化处理类的构造函数参数
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
可能日志处理器在并发写入时出现了冲突,导致日志系统检测到循环(比如一个日志写入触发了另一个日志记录,从而陷入死循环)。
我看了下support\Log类,以上代码,我在index控制器的test方法下使用了Log::channel('log2');,而Log的channel方法会判断isset(static::$instance[$name])结果,难道我在并发100次时,这些请求都是用同一个类?
Monolog
没有适配Swoole
,改Monolog
源码或者重写Logger
类,把深度检测关掉。多谢!通过useLoggingLoopDetection方法来关掉深度检测后,以上代码并发下的确不存在这个提示了