【问题标题】:Logging doesn't work in cakephp 3.3日志记录在 cakephp 3.3 中不起作用
【发布时间】:2017-02-28 23:04:33
【问题描述】:

无论何时我使用 LogTrait 或仅使用静态 Log 函数,都不会将任何内容输出到 debug.log 文件。我似乎无法弄清楚为什么。在 bootstrap.php 我看到这行代码:

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

这一定会导致app.php,但没有配置调试记录器。我没有从 app.php 中删除任何代码,所以我真的不明白它是如何突然停止工作的。在网站本身的调试栏中,我可以看到日志中发生了什么,但是如果我做一个重定向到另一个页面的发布请求,我看不到页面记录的内容,因为没有对“调试”进行任何更改.log”文件

我使用 CakePHP 中的 LogTrait 调用日志函数:

// 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');

【问题讨论】:

  • 您的日志文件和目录是否可被 Web 服务器进程写入?

标签: php cakephp logging cakephp-3.0


【解决方案1】:

在 App.php 中检查你的 Cakephp 是否处于调试模式

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

还可以使用 phpinfo() 或 php.ini 文件 var error_reporting 检查您的 php 配置

【讨论】:

    【解决方案2】:

    确保您的调试级别设置为 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'],
        ],
    ],
    

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2018-08-24
      • 2011-12-27
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      相关资源
      最近更新 更多