日志记录在cakephp 3.3中不工作


Logging doesn't work in cakephp 3.3

无论何时使用LogTrait还是仅仅使用静态Log函数,都不会输出到debug.log文件。我真的不知道为什么。在bootstrap.php中,我看到这行代码:

Log::config(Configure::consume('Log'));

这必须指向app.php,但没有配置调试日志记录器。我没有从app.php中删除任何代码,所以我真的不知道它是如何突然停止工作的。在网站本身的调试栏中,我可以看到日志中发生了什么,但如果我例如做一个重定向到另一个页面的post请求,我就看不到页面记录了什么,因为没有对"debug.log"文件进行任何更改

我调用日志函数要么使用LogTrait在CakePHP:

// I use the 'use LogTrait;' under the class declaration, and the 'use Cake'Log'LogTrait;' at the top of the file.
$this->log('message', 'debug');

或者调用静态函数:

'Cake'Log'Log::debug('message');

检查App.php是否为调试模式下的Cakephp

'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),

也检查你的php配置phpinfo()或php.ini文件var error_reporting

确保您的调试级别设置为1或2。我得到了类似的错误。在我的情况下,默认的app.php日志设置是不正确的。更新以下设置并重新启动服务器。

'Log' => [
    'debug' => [
        'className' => 'Cake'Log'Engine'ConsoleLog::class,
        'levels' => ['notice', 'info', 'debug'],
    ],
    'error' => [
        'className' => 'Cake'Log'Engine'ConsoleLog::class,
        'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
    ],
],