我是日志控,很多程序执行过程都要记录日志,队列生产时要记生产日志,队列消费时要记消费日志等等,而服务是在tmux中启动的,有时候希望直接在控制台里也能看见记录的日志,现在的做法是: $debugLogger->info('.....'); var_dumo('.....'); 也就是每一处记录日志的地方都要写两句,我记得monolog中好像可以配置同时记录文件并输出控制台,请问在webman中该怎么实现呢?
use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); $log->pushHandler(new StreamHandler('php://stdout', Logger::WARNING));
哦哦,原来是StreamHandler的php://stdout,谢谢。 那么只要这么配置channel就好了: 'debug' => [ 'handlers' => [ [ 'class' => Monolog\Handler\RotatingFileHandler::class, 'constructor' => [ runtime_path() . '/logs/debug.log', 7, //$maxFiles Monolog\Logger::DEBUG, ], 'formatter' => [ 'class' => Monolog\Formatter\LineFormatter::class, 'constructor' => [null, 'Y-m-d H:i:s.u', true], ], ], [ 'class' => Monolog\Handler\StreamHandler::class, 'constructor' => [ 'php://stdout', Monolog\Logger::DEBUG, ], 'formatter' => [ 'class' => Monolog\Formatter\LineFormatter::class, 'constructor' => [null, 'Y-m-d H:i:s.u', true], ], ] ], ]
棒棒的
哦哦,原来是StreamHandler的php://stdout,谢谢。
那么只要这么配置channel就好了:
'debug' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
runtime_path() . '/logs/debug.log',
7, //$maxFiles
Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s.u', true],
],
], [
'class' => Monolog\Handler\StreamHandler::class,
'constructor' => [
'php://stdout',
Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s.u', true],
],
]
],
]
棒棒的