Logging via PSR-3 Logger Interface


#1

Emergence provides a pre-configured logging facility implementing the PSR-3 logger interface via the Emergence\Logger class.

Writing to the log

To write to the log, you can instantiate the Emergence\Logger class, instantiate your own subclass of it, or utilize the default static singleton instance provided by Emergence\Logger::getLogger()

The Emergence\Logger class provides convenient static methods for logging to the default logger via static calls in the format general_[loglevel]:

\Emergence\Logger::general_warning($message, $context);

Reading log entries from the site log

Log entries with a level matching one configured in Emergence\Logger::$logLevelsWrite (warning through emergency by default) will be written to /emergence/sites/[siteHandle]/site-data/site.log. Additional log levels can be configured to be written via php-config/Emergence/Logger.config.php:

<?php
Emergence\Logger::$logLevelsWrite[] = \Psr\Log\LogLevel::INFO;

Receiving email alerts for log entries

Log entries with a level matching one configured in Emergence\Logger::$logLevelsWrite (critical through emergency by default) will be emailed to \Site::$webmasterEmail. Additional log levels can be configured to be emailed via php-config/Emergence/Logger.config.php:

<?php
Emergence\Logger::$logLevelsEmail[] = \Psr\Log\LogLevel::ERROR;

Using a custom logger instance for the default logger

You can provide your own logger instance for Emergence\Logger::getLogger() by setting the public static property Emergence\Logger::$logger via php-config/Emergence/Logger.config.php.