From d3e89dbed1175de4e0795f5b5b41d943b0dc789f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 2 May 2011 15:39:46 +0200 Subject: [PATCH] Added CRITICAL and ALERT levels --- README.mdown | 2 +- src/Monolog/Formatter/WildfireFormatter.php | 10 ++-- src/Monolog/Handler/SyslogHandler.php | 10 ++-- src/Monolog/Logger.php | 54 +++++++++++++++++---- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/README.mdown b/README.mdown index 11b53a49..83d0893c 100644 --- a/README.mdown +++ b/README.mdown @@ -26,7 +26,7 @@ You can create many Loggers, each defining a channel (e.g.: db, request, router, Each Handler also has a Formatter, a default one with settings that make sense will be created if you don't set one. The formatters normalize and format incoming records so that they can be used by the handlers to output useful information. -Custom severity levels are not available. Only four levels (debug, info, warning, error) are present for basic filtering purposes, but for sorting and other use cases that would require flexibility, you should add Processors to the Logger that can add extra information (tags, user ip, ..) to the records before they are handled. +Custom severity levels are not available. Only six levels (debug, info, warning, error, critical, alert) are present for basic filtering purposes, but for sorting and other use cases that would require flexibility, you should add Processors to the Logger that can add extra information (tags, user ip, ..) to the records before they are handled. Notable Features (non-exhaustive and incomplete) ------------------------------------------------ diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index 39512b4e..e51bbfab 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -29,10 +29,12 @@ class WildfireFormatter extends LineFormatter implements FormatterInterface * Translates Monolog log levels to Wildfire levels. */ private $logLevels = array( - Logger::DEBUG => 'LOG', - Logger::INFO => 'INFO', - Logger::WARNING => 'WARN', - Logger::ERROR => 'ERROR', + Logger::DEBUG => 'LOG', + Logger::INFO => 'INFO', + Logger::WARNING => 'WARN', + Logger::ERROR => 'ERROR', + Logger::CRITICAL => 'ERROR', + Logger::ALERT => 'ERROR', ); /** diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index d38900f1..dc8cc86e 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -33,10 +33,12 @@ class SyslogHandler extends AbstractHandler * Translates Monolog log levels to syslog log priorities. */ private $logLevels = array( - Logger::DEBUG => LOG_DEBUG, - Logger::INFO => LOG_INFO, - Logger::WARNING => LOG_WARNING, - Logger::ERROR => LOG_ERR, + Logger::DEBUG => LOG_DEBUG, + Logger::INFO => LOG_INFO, + Logger::WARNING => LOG_WARNING, + Logger::ERROR => LOG_ERR, + Logger::CRITICAL => LOG_CRIT, + Logger::ALERT => LOG_ALERT, ); /** diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index b4952244..49d1dfd4 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -27,12 +27,12 @@ class Logger /** * Debug messages */ - const DEBUG = 100; + const DEBUG = 100; /** * Messages you usually don't want to see */ - const INFO = 200; + const INFO = 200; /** * Exceptional occurences that are not errors @@ -44,13 +44,27 @@ class Logger /** * Errors */ - const ERROR = 400; + const ERROR = 400; + + /** + * Critical conditions (component unavailable, etc.) + */ + const CRITICAL = 500; + + /** + * Action must be taken immediately (entire service down) + * + * Should trigger alert by sms, email, etc. + */ + const ALERT = 550; protected static $levels = array( 100 => 'DEBUG', 200 => 'INFO', 300 => 'WARNING', 400 => 'ERROR', + 500 => 'CRITICAL', + 550 => 'ALERT', ); protected $name; @@ -206,6 +220,28 @@ class Logger return $this->addRecord(self::ERROR, $message); } + /** + * Adds a log record at the CRITICAL level. + * + * @param string $message The log message + * @return Boolean Whether the record has been processed + */ + public function addCritical($message) + { + return $this->addRecord(self::CRITICAL, $message); + } + + /** + * Adds a log record at the ALERT level. + * + * @param string $message The log message + * @return Boolean Whether the record has been processed + */ + public function addAlert($message) + { + return $this->addRecord(self::ALERT, $message); + } + /** * Gets the name of the logging level. * @@ -285,7 +321,7 @@ class Logger } /** - * Adds a log record at the ERROR level. + * Adds a log record at the CRITICAL level. * * This method allows to have an easy ZF compatibility. * @@ -294,11 +330,11 @@ class Logger */ public function crit($message) { - return $this->addRecord(self::ERROR, $message); + return $this->addRecord(self::CRITICAL, $message); } /** - * Adds a log record at the ERROR level. + * Adds a log record at the ALERT level. * * This method allows to have an easy ZF compatibility. * @@ -307,11 +343,11 @@ class Logger */ public function alert($message) { - return $this->addRecord(self::ERROR, $message); + return $this->addRecord(self::ALERT, $message); } /** - * Adds a log record at the ERROR level. + * Adds a log record at the ALERT level. * * This method allows to have an easy ZF compatibility. * @@ -320,6 +356,6 @@ class Logger */ public function emerg($message) { - return $this->addRecord(self::ERROR, $message); + return $this->addRecord(self::ALERT, $message); } }