Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

converted to using new severities as per RFC, updated shortcut method…

…s accordingly
  • Loading branch information...
commit 9ab47facbf23d4b7f2b6192969b911fdbcf13296 1 parent d4ba0ab
Brian Fenton authored
Showing with 92 additions and 20 deletions.
  1. +92 −20 src/KLogger.php
View
112 src/KLogger.php
@@ -23,14 +23,28 @@
class KLogger
{
/**
- * Error logging thresholds, from low to high
+ * Error severity, from low to high. From BSD syslog RFC, secion 4.1.1
+ * @link http://www.faqs.org/rfcs/rfc3164.html
*/
- const DEBUG = 1; // Most Verbose
- const INFO = 2; // ...
- const WARN = 3; // ...
- const ERROR = 4; // ...
- const FATAL = 5; // Least Verbose
- const OFF = 6; // Nothing at all.
+ const EMERG = 0; // Emergency: system is unusable
+ const ALERT = 1; // Alert: action must be taken immediately
+ const CRIT = 2; // Critical: critical conditions
+ const ERR = 3; // Error: error conditions
+ const WARN = 4; // Warning: warning conditions
+ const NOTICE = 5; // Notice: normal but significant condition
+ const INFO = 6; // Informational: informational messages
+ const DEBUG = 7; // Debug: debug messages
+
+ //custom logging level
+ /**
+ * Log nothing at all
+ */
+ const OFF = 8;
+ /**
+ * Alias for CRIT
+ * @deprecated
+ */
+ const FATAL = 2;
/**
* Internal status codes
@@ -48,12 +62,12 @@ class KLogger
* Holds messages generated by the class
* @var array
*/
- private $_messageQueue = array();
+ private $_messageQueue = array();
/**
* Path to the log file
* @var string
*/
- private $_logFilePath = null;
+ private $_logFilePath = null;
/**
* Current minimum logging threshold
* @var integer
@@ -63,7 +77,7 @@ class KLogger
* This holds the file handle for this instance's log file
* @var resource
*/
- private $_fileHandle = null;
+ private $_fileHandle = null;
/**
* Standard messages produced by the class. Can be modified for il8n
@@ -139,7 +153,7 @@ public function __construct($logDirectory, $severity)
{
$logDirectory = rtrim($logDirectory, '\\/');
- if ($severity == self::OFF) {
+ if ($severity === self::OFF) {
return;
}
@@ -178,6 +192,16 @@ public function __destruct()
fclose($this->_fileHandle);
}
}
+ /**
+ * Writes a $line to the log with a severity level of DEBUG
+ *
+ * @param string $line Information to log
+ * @return void
+ */
+ public function logDebug($line)
+ {
+ $this->log($line, self::DEBUG);
+ }
/**
* Returns (and removes) the last message from the queue.
@@ -207,7 +231,8 @@ public function clearMessages()
}
/**
- * Writes a $line to the log with a severity level of INFO
+ * Writes a $line to the log with a severity level of INFO. Any information
+ * can be used here, or it could be used with E_STRICT errors
*
* @param string $line Information to log
* @return void
@@ -218,18 +243,21 @@ public function logInfo($line)
}
/**
- * Writes a $line to the log with a severity level of DEBUG
+ * Writes a $line to the log with a severity level of NOTICE. Generally
+ * corresponds to E_STRICT, E_NOTICE, or E_USER_NOTICE errors
*
* @param string $line Information to log
* @return void
*/
- public function logDebug($line)
+ public function logNotice($line)
{
- $this->log($line, self::DEBUG);
+ $this->log($line, self::NOTICE);
}
/**
- * Writes a $line to the log with a severity level of WARN
+ * Writes a $line to the log with a severity level of WARN. Generally
+ * corresponds to E_WARNING, E_USER_WARNING, E_CORE_WARNING, or
+ * E_COMPILE_WARNING
*
* @param string $line Information to log
* @return void
@@ -240,21 +268,24 @@ public function logWarn($line)
}
/**
- * Writes a $line to the log with a severity level of ERROR
+ * Writes a $line to the log with a severity level of ERR. Most likely used
+ * with E_RECOVERABLE_ERROR
*
* @param string $line Information to log
* @return void
*/
public function logError($line)
{
- $this->log($line, self::ERROR);
+ $this->log($line, self::ERR);
}
/**
- * Writes a $line to the log with a severity level of FATAL
+ * Writes a $line to the log with a severity level of FATAL. Generally
+ * corresponds to E_ERROR, E_USER_ERROR, E_CORE_ERROR, or E_COMPILE_ERROR
*
* @param string $line Information to log
* @return void
+ * @deprecated Use logCrit
*/
public function logFatal($line)
{
@@ -262,6 +293,39 @@ public function logFatal($line)
}
/**
+ * Writes a $line to the log with a severity level of ALERT.
+ *
+ * @param string $line Information to log
+ * @return void
+ */
+ public function logAlert($line)
+ {
+ $this->log($line, self::ALERT);
+ }
+
+ /**
+ * Writes a $line to the log with a severity level of CRIT.
+ *
+ * @param string $line Information to log
+ * @return void
+ */
+ public function logCrit($line)
+ {
+ $this->log($line, self::FATAL);
+ }
+
+ /**
+ * Writes a $line to the log with a severity level of EMERG.
+ *
+ * @param string $line Information to log
+ * @return void
+ */
+ public function logEmerg($line)
+ {
+ $this->log($line, self::EMERG);
+ }
+
+ /**
* Writes a $line to the log with the given severity
*
* @param string $line Text to add to the log
@@ -296,13 +360,21 @@ private function _getTimeLine($level)
$time = date(self::$_dateFormat);
switch ($level) {
+ case self::EMERG:
+ return "$time - EMERG -->";
+ case self::ALERT:
+ return "$time - ALERT -->";
+ case self::CRIT:
+ return "$time - CRIT -->";
+ case self::NOTICE:
+ return "$time - NOTICE -->";
case self::INFO:
return "$time - INFO -->";
case self::WARN:
return "$time - WARN -->";
case self::DEBUG:
return "$time - DEBUG -->";
- case self::ERROR:
+ case self::ERR:
return "$time - ERROR -->";
case self::FATAL:
return "$time - FATAL -->";
Please sign in to comment.
Something went wrong with that request. Please try again.