gpt4 book ai didi

php - cakephp 3 在记录时使用范围

转载 作者:搜寻专家 更新时间:2023-10-31 21:28:06 24 4
gpt4 key购买 nike

我在 app.php 中为我的订单配置了一个记录器

'orders' => [
'className' => 'Cake\Log\Engine\FileLog',
'path' => LOGS,
'file' => 'orders',
'levels' => ['info'],
'scopes' => ['orders'],
]

然后在我的一个模型中我做了:

 Log::info("There's an order", 'orders');

我原以为日志消息只写在 orders.log 中,但它也显示在 debug.log 中。

根据文档:

If there is a configured logger for that scope, the log messages will be directed to those loggers. If a log message is written to an unknown scope, loggers that handle that level of message will log the message.

我做错了什么?

最佳答案

当我四处闲逛时,我发现了这个:https://github.com/DaoAndCo/cakephp-logging

要将范围限制为一个记录器,请将其添加到默认记录器配置中:

'scopes' => false

像这样:

'debug' => [
'className' => 'Cake\Log\Engine\FileLog',
'path' => LOGS,
'file' => 'debug',
'levels' => ['notice', 'info', 'debug'],
'scopes' => false,
'url' => env('LOG_DEBUG_URL', null),
],
'error' => [
'className' => 'Cake\Log\Engine\FileLog',
'path' => LOGS,
'file' => 'error',
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
'scopes' => false,
'url' => env('LOG_ERROR_URL', null),
],

就是这样!像魅力一样工作!我也做了测试。

关于php - cakephp 3 在记录时使用范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33284114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com