1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-14 09:04:15 +02:00

Use late static binding to allow people to extend Logger

This commit is contained in:
Aizat Faiz
2012-10-19 08:12:34 -07:00
parent fa292d1a94
commit 938b608c6c

View File

@@ -108,8 +108,8 @@ class Logger
{ {
$this->name = $name; $this->name = $name;
if (!self::$timezone) { if (!static::$timezone) {
self::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC'); static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');
} }
} }
@@ -183,15 +183,15 @@ class Logger
public function addRecord($level, $message, array $context = array()) public function addRecord($level, $message, array $context = array())
{ {
if (!$this->handlers) { if (!$this->handlers) {
$this->pushHandler(new StreamHandler('php://stderr', self::DEBUG)); $this->pushHandler(new StreamHandler('php://stderr', static::DEBUG));
} }
$record = array( $record = array(
'message' => (string) $message, 'message' => (string) $message,
'context' => $context, 'context' => $context,
'level' => $level, 'level' => $level,
'level_name' => self::getLevelName($level), 'level_name' => static::getLevelName($level),
'channel' => $this->name, 'channel' => $this->name,
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)))->setTimeZone(self::$timezone), 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)))->setTimeZone(static::$timezone),
'extra' => array(), 'extra' => array(),
); );
// check if any handler will handle this message // check if any handler will handle this message
@@ -227,7 +227,7 @@ class Logger
*/ */
public function addDebug($message, array $context = array()) public function addDebug($message, array $context = array())
{ {
return $this->addRecord(self::DEBUG, $message, $context); return $this->addRecord(static::DEBUG, $message, $context);
} }
/** /**
@@ -239,7 +239,7 @@ class Logger
*/ */
public function addInfo($message, array $context = array()) public function addInfo($message, array $context = array())
{ {
return $this->addRecord(self::INFO, $message, $context); return $this->addRecord(static::INFO, $message, $context);
} }
/** /**
@@ -251,7 +251,7 @@ class Logger
*/ */
public function addNotice($message, array $context = array()) public function addNotice($message, array $context = array())
{ {
return $this->addRecord(self::NOTICE, $message, $context); return $this->addRecord(static::NOTICE, $message, $context);
} }
/** /**
@@ -263,7 +263,7 @@ class Logger
*/ */
public function addWarning($message, array $context = array()) public function addWarning($message, array $context = array())
{ {
return $this->addRecord(self::WARNING, $message, $context); return $this->addRecord(static::WARNING, $message, $context);
} }
/** /**
@@ -275,7 +275,7 @@ class Logger
*/ */
public function addError($message, array $context = array()) public function addError($message, array $context = array())
{ {
return $this->addRecord(self::ERROR, $message, $context); return $this->addRecord(static::ERROR, $message, $context);
} }
/** /**
@@ -287,7 +287,7 @@ class Logger
*/ */
public function addCritical($message, array $context = array()) public function addCritical($message, array $context = array())
{ {
return $this->addRecord(self::CRITICAL, $message, $context); return $this->addRecord(static::CRITICAL, $message, $context);
} }
/** /**
@@ -299,7 +299,7 @@ class Logger
*/ */
public function addAlert($message, array $context = array()) public function addAlert($message, array $context = array())
{ {
return $this->addRecord(self::ALERT, $message, $context); return $this->addRecord(static::ALERT, $message, $context);
} }
/** /**
@@ -311,7 +311,7 @@ class Logger
*/ */
public function addEmergency($message, array $context = array()) public function addEmergency($message, array $context = array())
{ {
return $this->addRecord(self::EMERGENCY, $message, $context); return $this->addRecord(static::EMERGENCY, $message, $context);
} }
/** /**
@@ -322,7 +322,7 @@ class Logger
*/ */
public static function getLevelName($level) public static function getLevelName($level)
{ {
return self::$levels[$level]; return static::$levels[$level];
} }
/** /**
@@ -337,7 +337,7 @@ class Logger
'message' => '', 'message' => '',
'context' => array(), 'context' => array(),
'level' => $level, 'level' => $level,
'level_name' => self::getLevelName($level), 'level_name' => static::getLevelName($level),
'channel' => $this->name, 'channel' => $this->name,
'datetime' => new \DateTime(), 'datetime' => new \DateTime(),
'extra' => array(), 'extra' => array(),
@@ -363,7 +363,7 @@ class Logger
*/ */
public function debug($message, array $context = array()) public function debug($message, array $context = array())
{ {
return $this->addRecord(self::DEBUG, $message, $context); return $this->addRecord(static::DEBUG, $message, $context);
} }
/** /**
@@ -377,7 +377,7 @@ class Logger
*/ */
public function info($message, array $context = array()) public function info($message, array $context = array())
{ {
return $this->addRecord(self::INFO, $message, $context); return $this->addRecord(static::INFO, $message, $context);
} }
/** /**
@@ -391,7 +391,7 @@ class Logger
*/ */
public function notice($message, array $context = array()) public function notice($message, array $context = array())
{ {
return $this->addRecord(self::NOTICE, $message, $context); return $this->addRecord(static::NOTICE, $message, $context);
} }
/** /**
@@ -405,7 +405,7 @@ class Logger
*/ */
public function warn($message, array $context = array()) public function warn($message, array $context = array())
{ {
return $this->addRecord(self::WARNING, $message, $context); return $this->addRecord(static::WARNING, $message, $context);
} }
/** /**
@@ -419,7 +419,7 @@ class Logger
*/ */
public function err($message, array $context = array()) public function err($message, array $context = array())
{ {
return $this->addRecord(self::ERROR, $message, $context); return $this->addRecord(static::ERROR, $message, $context);
} }
/** /**
@@ -433,7 +433,7 @@ class Logger
*/ */
public function crit($message, array $context = array()) public function crit($message, array $context = array())
{ {
return $this->addRecord(self::CRITICAL, $message, $context); return $this->addRecord(static::CRITICAL, $message, $context);
} }
/** /**
@@ -447,7 +447,7 @@ class Logger
*/ */
public function alert($message, array $context = array()) public function alert($message, array $context = array())
{ {
return $this->addRecord(self::ALERT, $message, $context); return $this->addRecord(static::ALERT, $message, $context);
} }
/** /**
@@ -461,6 +461,6 @@ class Logger
*/ */
public function emerg($message, array $context = array()) public function emerg($message, array $context = array())
{ {
return $this->addRecord(self::EMERGENCY, $message, $context); return $this->addRecord(static::EMERGENCY, $message, $context);
} }
} }