Laravel流明-对数通道

问题描述 投票:4回答:1

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

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

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

如何在流明中做到这一点?

我通过channels 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仓库中看到它,但不在laravel / lumen中)

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

php laravel lumen
1个回答
0
投票

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

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

...

$log1->info('msg1');
...
$log2->info('msg2');
...

当然,您必须像Laravel中一样创建一个config / logging.php。在此定义“ case1”和“ case2”通道。框架会自动识别。

© www.soinside.com 2019 - 2024. All rights reserved.