Cakephp 3在日志记录时使用作用域


cakephp 3 using scopes when logging

我为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中。

根据文档:

如果为该范围配置了记录器,则日志消息将被引导到那些伐木工人那里。如果将日志消息写入未知范围,处理该级别消息的日志记录器将记录消息。

我做错了什么?

当我四处游荡时,我发现了这个: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),
],

就是这样!努力工作吧!我也测试过了

'queries' =>['className' =>FileLog::class, 'path' =>日志,'file' =>'查询','url' =>env('LOG_QUERIES_URL', null), 'scopes' =>[' queriesLog ']],