CakePHP:日志范围

时间:2016-04-02 12:44:30

标签: cakephp cakephp-3.0

我已添加此日志配置:

Log::config('users', [
    'className' => 'FileLog',
    'path' => LOGS,
    'levels' => [],
    'scopes' => ['users'],
    'file' => 'users.log'
]);

现在我正试着用这样的东西写作:

Log::warning(sprintf(
     '%s - Failed login with username `%s` and password `%s`',
     $this->request->clientIp(),
     $this->request->data('username'),
     $this->request->data('password')
), ['scope' => ['users']]);

或(它应该是相同的(或不是?)):

Log::warning(sprintf(
     '%s - Failed login with username `%s` and password `%s`',
     $this->request->clientIp(),
     $this->request->data('username'),
     $this->request->data('password')
), 'users');

问题是日志是用users.logerror.log编写的,而我希望日志只在第一个中写入({{1} })。

有什么问题?

1 个答案:

答案 0 :(得分:0)

config/app.php中找到的CakePHP日志的默认配置是:

// ...
'Log' => [
    // ...
    'error' => [
        'className' => 'Cake\Log\Engine\FileLog',
        'path' => LOGS,
        'file' => 'error',
        'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
    ],
    // ...

告诉你的应用写下所有"警告"级别记录到error.log

如果您正在进行自定义日志记录,则可能需要禁用某些默认值才能满足您的要求