0

I am new to php and its framework. I have followed the official guide line about how to add the ChromeLogger in Logger.php. I have also added the chrome extension for Chrome Logger.

How do I see any logging information on my controller?

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

}
Vickel
  • 7,879
  • 6
  • 35
  • 56
Long Ranger
  • 5,888
  • 8
  • 43
  • 72
  • as you state you are new to php and CI framework, please keep in mind codeigniter 4.x is a complete re-write of the framework, the latest 4.x version is a release candidate 4.0.0-rc.3. More answers and resources could be found here: https://forum.codeigniter.com/index.php – Vickel Dec 27 '19 at 23:28
  • @Vickel Thank you for the editting. But I cannot find any related information in this forum. Also, the documentation of Codeiginiter-4 on Logger and the comment on Logger.php is quite straightforward for the developer to add the ChromeLogger Handler. So I think I must do something wrong but i cannot figure out which part is incorrect. – Long Ranger Dec 28 '19 at 10:40

1 Answers1

0

First of all check your threshold in app\Config\Logger.php:

public $threshold = 4;

factory default is 4, but to log 'info' level messages $threshold should be 7!

Second, you can verify that you server is sending ChromeLogger data in your browser Dev tools (Network -> Header -> Response). Header:

X-ChromeLogger-Data: ...

should be included.

Third, looks like original ChromeLogger extension is not working in Chrome, but it works fine in 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.

blagi
  • 26
  • 4