78 const EMERGENCY = 600;
95 protected static $levels = array(
98 self::NOTICE =>
'NOTICE',
99 self::WARNING =>
'WARNING',
100 self::ERROR =>
'ERROR',
101 self::CRITICAL =>
'CRITICAL',
102 self::ALERT =>
'ALERT',
103 self::EMERGENCY =>
'EMERGENCY',
135 protected $microsecondTimestamps =
true;
150 $this->setHandlers($handlers);
151 $this->processors = $processors;
183 array_unshift($this->handlers, $handler);
195 if (!$this->handlers) {
196 throw new \LogicException(
'You tried to pop from an empty handler stack.');
199 return array_shift($this->handlers);
212 $this->handlers = array();
213 foreach (array_reverse($handlers) as
$handler) {
214 $this->pushHandler($handler);
225 return $this->handlers;
236 if (!is_callable($callback)) {
237 throw new \InvalidArgumentException(
'Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback,
true).
' given');
239 array_unshift($this->processors, $callback);
251 if (!$this->processors) {
252 throw new \LogicException(
'You tried to pop from an empty processor stack.');
255 return array_shift($this->processors);
263 return $this->processors;
281 $this->microsecondTimestamps = (bool) $micro;
294 if (!$this->handlers) {
298 $levelName = static::getLevelName($level);
302 reset($this->handlers);
303 while (
$handler = current($this->handlers)) {
304 if (
$handler->isHandling(array(
'level' => $level))) {
305 $handlerKey = key($this->handlers);
309 next($this->handlers);
312 if (null === $handlerKey) {
316 if (!static::$timezone) {
317 static::$timezone = new \DateTimeZone(date_default_timezone_get() ?:
'UTC');
321 if ($this->microsecondTimestamps && PHP_VERSION_ID < 70100) {
322 $ts = \DateTime::createFromFormat(
'U.u', sprintf(
'%.6F', microtime(
true)), static::$timezone);
324 $ts = new \DateTime(null, static::$timezone);
326 $ts->setTimezone(static::$timezone);
332 'level_name' => $levelName,
333 'channel' => $this->name,
339 foreach ($this->processors as $processor) {
340 $record = call_user_func($processor, $record);
343 while (
$handler = current($this->handlers)) {
344 if (
true ===
$handler->handle($record)) {
348 next($this->handlers);
351 $this->handleException($e, $record);
369 foreach ($this->handlers as
$handler) {
370 if (method_exists($handler,
'close')) {
388 foreach ($this->handlers as
$handler) {
394 foreach ($this->processors as $processor) {
504 return array_flip(static::$levels);
515 if (!isset(static::$levels[$level])) {
516 throw new InvalidArgumentException(
'Level "'.$level.
'" is not defined, use one of: '.implode(
', ', array_keys(static::$levels)));
519 return static::$levels[$level];
530 if (is_string($level) && defined(__CLASS__.
'::'.strtoupper($level))) {
531 return constant(__CLASS__.
'::'.strtoupper($level));
549 foreach ($this->handlers as
$handler) {
550 if ($handler->isHandling($record)) {
566 if (!is_callable($callback)) {
567 throw new \InvalidArgumentException(
'Exception handler must be valid callable (callback or object with an __invoke method), '.var_export($callback,
true).
' given');
569 $this->exceptionHandler = $callback;
579 return $this->exceptionHandler;
588 if (!$this->exceptionHandler) {
592 call_user_func($this->exceptionHandler, $e, $record);
607 $level = static::toMonologLevel($level);
789 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.
Handler or Processor implementing this interface will be reset when Logger::reset() is called...
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.
close()
Ends a log cycle and frees all resources used by handlers.
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.
handleException(Exception $e, array $record)
Delegates exception management to the custom exception handler, or throws the exception if no custom ...
warn($message, array $context=array())
Adds a log record at the WARNING level.
reset()
Ends a log cycle and resets all handlers and processors to their initial state.
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.
setExceptionHandler($callback)
Set a custom exception handler.
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.
Interface that all Monolog Handlers must implement.
addInfo($message, array $context=array())
Adds a log record at the INFO level.