无法在Codeigniter4中触发ChromeLogger处理程序

时间:2019-12-27 21:41:30

标签: php codeigniter codeigniter-4 chromelogger

我是php及其框架的新手。我遵循了关于how to add the ChromeLogger in Logger.php的官方指南。我还为Chrome Logger添加了chrome扩展名。

如何查看控制器上的任何日志记录信息?

Logger.php

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Logger extends BaseConfig
{
    ...
    public $handlers = [

        //--------------------------------------------------------------------
        // File Handler
        //--------------------------------------------------------------------

        'CodeIgniter\Log\Handlers\FileHandler' => [

            /*
             * The log levels that this handler will handle.
             */
            'handles'         => [
                'critical',
                'alert',
                'emergency',
                'debug',
                'error',
                'info',
                'notice',
                'warning',
            ],

            /*
             * Leave this BLANK unless you would like to set something other than the default
             * writeable/logs/ directory. Use a full getServer path with trailing slash.
             */
            'path'            => WRITEPATH . 'logs/',

            /*
             * The default filename extension for log files. The default 'php' allows for
             * protecting the log files via basic scripting, when they are to be stored
             * under a publicly accessible directory.
             *
             * Note: Leaving it blank will default to 'php'.
             */
            'fileExtension'   => 'php',

            /*
             * The file system permissions to be applied on newly created log files.
             *
             * IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
             * integer notation (i.e. 0700, 0644, etc.)
             */
            'filePermissions' => 0644,
        ],

        /**
         * The ChromeLoggerHandler requires the use of the Chrome web browser
         * and the ChromeLogger extension. Uncomment this block to use it.
         */
        'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
            /*
                  * The log levels that this handler will handle.
                  */
            'handles' => [
                'critical', 'alert', 'emergency', 'debug',
                'error', 'info', 'notice', 'warning'
            ],
        ]
    ];
}

News.php

<?php

namespace App\Controllers;

use App\Models\NewsModel;
use CodeIgniter\Controller;


class News extends Controller
{
    public function index()
    {
        log_message('info', 'News Index page is visited');
        $model = new NewsModel();

        $data = [
            'news'  => $model->getNews(),
            'title' => 'News archive',
        ];

        echo view('templates/header', $data);
        echo view('news/overview', $data);
        echo view('templates/footer');
    }

}

1 个答案:

答案 0 :(得分:0)

首先在app \ Config \ Logger.php中检查您的阈值:

public $threshold = 4;

出厂默认值为4,但要记录“信息”级消息$ threshold,则应为7!

第二,您可以在浏览器开发工具(网络->标头->响应)中确认服务器正在发送ChromeLogger数据。标题:

X-ChromeLogger数据: ...

应包括在内。

第三,看起来原始的ChromeLogger扩展程序无法在Chrome中运行,但在Firefox中可以正常运行。日志消息应该在开发工具控制台中。

我安装了此扩展程序:

Server log by Rasmus Schultz

通过在新的开发工具选项卡“服务器日志”中添加日志信息来工作。 它还支持新的日志标题 X-ServerLog-Location