Biplob Hossain

concrete5 Logging

December 10, 2016 | by biplob.ice

concrete5-logging

Logging

When building in concrete5, sometimes it’s hard to understand what is happening at particular points in your code’s execution. This is especially true when working with Ajax since the executed code isn’t even running in your browser. For these reasons and others, logging variables or entire sections of output so you can inspect them once execution has been completed is a sensible thing to do during development.

concrete5 has an event log in the dashboard. Typically you’ll find exceptions and email-sending events logged there, but you can add your entries to this log using the concrete5 logger library and this simple code:

Loading the Library

        use Concrete\Core\Logging\Logger

Viewing the Logs

Logs can be viewed and searched in Dashboard > Reports > Logs.

Adding an entry to the Log

You can add messages to the log with different levels. To quickly add a single entry to the log, use any of the following methods depending on your log level.

        $l = new Logger('My-Channel');             // You can filter logs by channel

        // To add a custom message
        $l->debug('This is a debug message');

        // If you want to print an array variable
        $l->debug('MyArray: ' . print_r($myArray, true));

It will appear in the dashboard immediately.

Methods

$log->alert($message)

Adds an alert level message to the current log object.

$log->info($message)

Adds an info-level message to the current log object.

$log->debug($message)

Adds a debug-level message to the current log object.

$log->emergency($message)

Adds an emergency-level message to the current log object.

$log->critical($message)

Adds a critical-level message to the current log object.

RELATED POSTS

View all

view all