SatisPress implements a PSR-3 Logger Interface for logging messages when WP_DEBUG
is enabled. The default implementation only logs messages with a log level of warning
or higher.
Messages are logged via PHP's error_log()
function, which typically saves them to the wp-content/debug.log
file when WP_DEBUG
is enabled.
To log more or less information, the log level can be adjusted in the DI container.
<?php
add_action( 'satispress_compose', function( $plugin, $container ) {
$container['logger.level'] = 'debug';
}, 10, 2 );
Assigning an empty string or invalid level will prevent messages from being logged, effectively disabling the logger.
The example below demonstrates how to retrieve the SatisPress container and register a new logger to replace the default logger. It uses Monolog to send warning messages through PHP's error_log()
handler:
<?php
use Monolog\Logger;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Processor\PsrLogMessageProcessor;
/**
* Register the logger before SatisPress is composed.
*/
add_action( 'satispress_compose', function( $plugin, $container ) {
$container['logger'] = function() {
$logger = new Logger( 'satispress' );
$logger->pushHandler( new ErrorLogHandler( ErrorLogHandler::OPERATING_SYSTEM, LOGGER::WARNING ) );
$logger->pushProcessor( new PsrLogMessageProcessor );
return $logger;
};
}, 10, 2 );
Monolog should be required with Composer and the autoloader needs to be included before using it in your project.