concrete5 Logging

MD Biplob Hossain
MD Biplob Hossain

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 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 own 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 entry to the Log

You can add messages to log with different levels. To quickly add a single entry to the log, use any of the following method 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 a alert level message to the current log object.

$log->info($message)

Adds a 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 a emergency level message to the current log object.

$log->critical($message)

Adds a critical level message to the current log object.