77 const EMERGENCY = 600;
94 protected static $levels =
array(
97 self::NOTICE =>
'NOTICE',
98 self::WARNING =>
'WARNING',
99 self::ERROR =>
'ERROR',
100 self::CRITICAL =>
'CRITICAL',
101 self::ALERT =>
'ALERT',
102 self::EMERGENCY =>
'EMERGENCY',
134 protected $microsecondTimestamps =
true;
144 $this->handlers = $handlers;
145 $this->processors = $processors;
177 array_unshift($this->handlers, $handler);
189 if (!$this->handlers) {
190 throw new \LogicException(
'You tried to pop from an empty handler stack.');
193 return array_shift($this->handlers);
206 $this->handlers =
array();
207 foreach (array_reverse($handlers) as
$handler) {
208 $this->pushHandler($handler);
219 return $this->handlers;
230 if (!is_callable($callback)) {
231 throw new \InvalidArgumentException(
'Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback,
true).
' given');
233 array_unshift($this->processors, $callback);
245 if (!$this->processors) {
246 throw new \LogicException(
'You tried to pop from an empty processor stack.');
249 return array_shift($this->processors);
257 return $this->processors;
275 $this->microsecondTimestamps = (bool) $micro;
288 if (!$this->handlers) {
292 $levelName = static::getLevelName($level);
296 reset($this->handlers);
297 while (
$handler = current($this->handlers)) {
299 $handlerKey = key($this->handlers);
303 next($this->handlers);
306 if (null === $handlerKey) {
310 if (!static::$timezone) {
311 static::$timezone = new \DateTimeZone(date_default_timezone_get() ?:
'UTC');
314 if ($this->microsecondTimestamps) {
315 $ts = \DateTime::createFromFormat(
'U.u', sprintf(
'%.6F', microtime(
true)), static::$timezone);
317 $ts = new \DateTime(null, static::$timezone);
319 $ts->setTimezone(static::$timezone);
323 'context' => $context,
325 'level_name' => $levelName,
326 'channel' => $this->name,
331 foreach ($this->processors as $processor) {
332 $record = call_user_func($processor, $record);
335 while (
$handler = current($this->handlers)) {
336 if (
true ===
$handler->handle($record)) {
340 next($this->handlers);
367 return $this->addRecord(static::INFO,
$message, $context);
379 return $this->addRecord(static::NOTICE,
$message, $context);
391 return $this->addRecord(static::WARNING,
$message, $context);
403 return $this->addRecord(static::ERROR,
$message, $context);
415 return $this->addRecord(static::CRITICAL,
$message, $context);
427 return $this->addRecord(static::ALERT,
$message, $context);
439 return $this->addRecord(static::EMERGENCY,
$message, $context);
449 return array_flip(static::$levels);
460 if (!isset(static::$levels[$level])) {
461 throw new InvalidArgumentException(
'Level "'.$level.
'" is not defined, use one of: '.implode(
', ', array_keys(static::$levels)));
464 return static::$levels[$level];
475 if (is_string($level) &&
defined(__CLASS__.
'::'.strtoupper($level))) {
476 return constant(__CLASS__.
'::'.strtoupper($level));
494 foreach ($this->handlers as
$handler) {
495 if ($handler->isHandling($record)) {
515 $level = static::toMonologLevel($level);
517 return $this->addRecord($level,
$message, $context);
545 return $this->addRecord(static::INFO,
$message, $context);
559 return $this->addRecord(static::NOTICE,
$message, $context);
573 return $this->addRecord(static::WARNING,
$message, $context);
587 return $this->addRecord(static::WARNING,
$message, $context);
601 return $this->addRecord(static::ERROR,
$message, $context);
615 return $this->addRecord(static::ERROR,
$message, $context);
629 return $this->addRecord(static::CRITICAL,
$message, $context);
643 return $this->addRecord(static::CRITICAL,
$message, $context);
657 return $this->addRecord(static::ALERT,
$message, $context);
671 return $this->addRecord(static::EMERGENCY,
$message, $context);
685 return $this->addRecord(static::EMERGENCY,
$message, $context);
697 self::$timezone =
$tz;
addDebug($message, array $context=array())
Adds a log record at the DEBUG level.
crit($message, array $context=array())
Adds a log record at the CRITICAL level.
addWarning($message, array $context=array())
Adds a log record at the WARNING level.
warning($message, array $context=array())
Adds a log record at the WARNING level.
info($message, array $context=array())
Adds a log record at the INFO level.
popProcessor()
Removes the processor on top of the stack and returns it.
err($message, array $context=array())
Adds a log record at the ERROR level.
addAlert($message, array $context=array())
Adds a log record at the ALERT level.
isHandling($level)
Checks whether the Logger has a handler that listens on the given level.
emergency($message, array $context=array())
Adds a log record at the EMERGENCY level.
static setTimezone(\DateTimeZone $tz)
Set the timezone to be used for the timestamp of log records.
addEmergency($message, array $context=array())
Adds a log record at the EMERGENCY level.
log($level, $message, array $context=array())
Adds a log record at an arbitrary level.
setHandlers(array $handlers)
Set handlers, replacing all existing ones.
critical($message, array $context=array())
Adds a log record at the CRITICAL level.
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
alert($message, array $context=array())
Adds a log record at the ALERT level.
addError($message, array $context=array())
Adds a log record at the ERROR level.
popHandler()
Pops a handler from the stack.
__construct($name, array $handlers=array(), array $processors=array())
debug($message, array $context=array())
Adds a log record at the DEBUG level.
pushHandler(HandlerInterface $handler)
Pushes a handler on to the stack.
catch(Exception $e) $message
addNotice($message, array $context=array())
Adds a log record at the NOTICE level.
withName($name)
Return a new cloned instance with the name changed.
emerg($message, array $context=array())
Adds a log record at the EMERGENCY level.
addRecord($level, $message, array $context=array())
Adds a log record.
warn($message, array $context=array())
Adds a log record at the WARNING level.
Create styles array
The data for the language used.
static getLevels()
Gets all supported logging levels.
Describes a logger instance.
useMicrosecondTimestamps($micro)
Control the use of microsecond resolution timestamps in the 'datetime' member of new records...
Stores to any stream resource.
notice($message, array $context=array())
Adds a log record at the NOTICE level.
static getLevelName($level)
Gets the name of the logging level.
addCritical($message, array $context=array())
Adds a log record at the CRITICAL level.
error($message, array $context=array())
Adds a log record at the ERROR level.
pushProcessor($callback)
Adds a processor on to the stack.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Interface that all Monolog Handlers must implement.
addInfo($message, array $context=array())
Adds a log record at the INFO level.