Logging Events

Once initialized, the DecaLog SDK is ready to trigger events.
To do so, just ask the Engine to return a PSR-3 logger for your already registered slug and use it like any other PSR-3 logger:

<?php $events = \DecaLog\Engine::eventsLogger( 'my-plugin-slug' ); $events->info( 'This is an information.' ); $events->error( 'This is an error with a code.', [ 'code' => 500 ] );
Code language: PHP (php)

There are 8 methods – from debug() to emergency() – you can use:

/** * Logs a panic condition. WordPress is unusable. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function emergency( $message, $context = [] ) {} /** * Logs a major operating error that undoubtedly affects the operations. * It requires immediate investigation and corrective treatment. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function alert( $message, $context = [] ) {} /** * Logs an operating error that undoubtedly affects the operations. * It requires investigation and corrective treatment. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function critical( $message, $context = [] ) {} /** * Logs a minor operating error that may affects the operations. * It requires investigation and preventive treatment. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function error( $message, $context = [] ) {} /** * Logs a significant condition indicating a situation that may lead to an error if recurring or if no action is taken. * Does not usually affect the operations. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function warning( $message, $context = [] ) {} /** * Logs a normal but significant condition. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function notice( $message, $context = [] ) {} /** * Logs a standard information. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function info( $message, $context = [] ) {} /** * Logs an information for developers and testers. * Only used for events related to application/system debugging. * * @param string $message The message to log. * @param array $context Optional. The context of the event. * FYI, DecaLog has its own context-aware logging system. The only element of context * that you can pass to DecaLog is a numerical error code ($context['code']). All other * element of context will be removed. * @return void * @since 1.0.0 */ public function debug( $message, $context = [] ) {}
Code language: PHP (php)

Logging events at a specific level

Like any PSR-3 logger, in addition to the 8 previous methods, DecaLog offers a method to specify the level of the event as an argument:

<?php $events = \DecaLog\Engine::eventsLogger( 'my-plugin-slug' ); $events->log( \Psr\Log\LogLevel::INFO, 'This is an information' ); $events->log( \Psr\Log\LogLevel::ERROR, 'This is an error with a code.', [ 'code' => 500 ] );
Code language: PHP (php)

Limitations

Any events triggered after the DECALOG_MAX_SHUTDOWN_PRIORITY in the WordPress shutdown hook may be dropped by DecaLog.

<?php // The following error will be logged: add_action( 'shutdown', function() { \DecaLog\Engine::eventsLogger( 'my-plugin-slug' )->error( 'This error is logged.' ); }, DECALOG_MAX_SHUTDOWN_PRIORITY, 0 ); // The following error may not be logged: add_action( 'shutdown', function() { \DecaLog\Engine::eventsLogger( 'my-plugin-slug' )->error( 'This error may not be logged.' ); }, DECALOG_MAX_SHUTDOWN_PRIORITY + 1, 0 );
Code language: PHP (php)