简体   繁体   English

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

[英]Cannot trigger ChromeLogger Handler in Codeigniter4

I am new to php and its framework.我是 php 及其框架的新手。 I have followed the official guide line about how to add the ChromeLogger in Logger.php .我遵循了关于如何在 Logger.php 中添加 ChromeLogger的官方指南。 I have also added the chrome extension for Chrome Logger .我还为Chrome Logger添加了 chrome 扩展。

How do I see any logging information on my controller?如何查看控制器上的任何日志信息?

Logger.php记录器.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

<?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');
    }

}

First of all check your threshold in app\\Config\\Logger.php:首先在 app\\Config\\Logger.php 中检查您的阈值:

public $threshold = 4;

factory default is 4, but to log 'info' level messages $threshold should be 7!出厂默认值为 4,但要记录“信息”级别的消息,$threshold 应为 7!

Second, you can verify that you server is sending ChromeLogger data in your browser Dev tools (Network -> Header -> Response).其次,您可以在浏览器开发工具(网络 -> 标头 -> 响应)中验证您的服务器是否正在发送 ChromeLogger 数据。 Header:标题:

X-ChromeLogger-Data: ... X-ChromeLogger-数据: ...

should be included.应该包括在内。

Third, looks like original ChromeLogger extension is not working in Chrome, but it works fine in Firefox.第三,看起来原来的 ChromeLogger 扩展在 Chrome 中不起作用,但它在 Firefox 中运行良好。 Log message should be in Dev tools Console.日志消息应该在开发工具控制台中。

I installed this extension:我安装了这个扩展:

Server log by Rasmus Schultz 拉斯穆斯舒尔茨的服务器日志

It works by adding log info in new Dev tools tab "Server Log".它的工作原理是在新的开发工具选项卡“服务器日志”中添加日志信息。 it also supports new log header X-ServerLog-Location .它还支持新的日志头X-ServerLog-Location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM