【问题标题】:cakephp 3 using scopes when loggingcakephp 3 在记录时使用范围
【发布时间】:2015-10-22 14:56:01
【问题描述】:

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

根据文档:

如果为该范围配置了记录器,则日志消息将 被定向到那些记录器。如果将日志消息写入 未知范围,处理该级别消息的记录器将记录 消息。

我做错了什么?

【问题讨论】:

  • 可能值得简单地调试where the log method looks for a stream
  • 所以默认行为是没有范围的记录器将捕获所有消息(如果它们匹配其级别),对吗?我来自 cake 2,它的工作方式不同,但我现在看到这是因为 cake 2 允许您使用自定义级别(类型),因此您可以在 cake 3 中执行write('orders', 'message', 'orders'),这会产生异常。我说的对吗?

标签: php cakephp cakephp-3.0


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 2016-04-28
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多