Laravel Lumen - 日志通道

Fra*_*alf 5 php laravel lumen

对于两种不同的情况,我需要登录到两个不同的文件。像这样的东西:

Log::channel('case1')->info('msg1'),

Log::channel('case2')->info('msg2'),

我怎样才能在 Lumen 中做到这一点?

我通过频道 https://laravel.com/docs/5.6/logging#customizing-monolog-for-channels阅读了 Laravel 这样做的方式,然后调用这样的频道:Log::channel('custom-channel')->info('msg'),但是你如何使用 Lumen 实现这一点?我似乎找不到该config/logging.php文件(我只在 src 之外的 laravel/lumen-framework repo 中看到它,但它不在 laravel/lumen 中)

如果您知道如何实现这一点,请提供一些代码示例。谢谢 :)

Art*_*hur 1

在这种情况下对我有用的是:

$log1 = app('Psr\Log\LoggerInterface')->channel('case1');
$log2 = app('Psr\Log\LoggerInterface')->channel('case2');

...

$log1->info('msg1');
...
$log2->info('msg2');
...
Run Code Online (Sandbox Code Playgroud)

当然,您必须像 Laravel 中一样创建 config/logging.php。您可以在此处定义“case1”和“case2”通道。这会被框架自动获取。