Documentation

Logger
in package
implements LoggerInterface, ResettableInterface

Monolog log channel

It contains a stack of Handlers and a stack of Processors, and uses them to store records that are added to it.

Tags
author

Jordi Boggiano j.boggiano@seld.be

Table of Contents

Interfaces

LoggerInterface
Describes a logger instance.
ResettableInterface
Handler or Processor implementing this interface will be reset when Logger::reset() is called.

Constants

ALERT  = 550
Action must be taken immediately
API  = 1
Monolog API version
CRITICAL  = 500
Critical conditions
DEBUG  = 100
Detailed debug information
EMERGENCY  = 600
Urgent alert.
ERROR  = 400
Runtime errors
INFO  = 200
Interesting events
NOTICE  = 250
Uncommon events
WARNING  = 300
Exceptional occurrences that are not errors

Properties

$exceptionHandler  : callable
$handlers  : array<string|int, HandlerInterface>
The handler stack
$levels  : array<string|int, mixed>
Logging levels from syslog protocol defined in RFC 5424
$microsecondTimestamps  : bool
$name  : string
$processors  : array<string|int, callable>
Processors that will process all log records
$timezone  : DateTimeZone

Methods

__construct()  : mixed
addAlert()  : bool
Adds a log record at the ALERT level.
addCritical()  : bool
Adds a log record at the CRITICAL level.
addDebug()  : bool
Adds a log record at the DEBUG level.
addEmergency()  : bool
Adds a log record at the EMERGENCY level.
addError()  : bool
Adds a log record at the ERROR level.
addInfo()  : bool
Adds a log record at the INFO level.
addNotice()  : bool
Adds a log record at the NOTICE level.
addRecord()  : bool
Adds a log record.
addWarning()  : bool
Adds a log record at the WARNING level.
alert()  : bool
Adds a log record at the ALERT level.
close()  : mixed
Ends a log cycle and frees all resources used by handlers.
crit()  : bool
Adds a log record at the CRITICAL level.
critical()  : bool
Adds a log record at the CRITICAL level.
debug()  : bool
Adds a log record at the DEBUG level.
emerg()  : bool
Adds a log record at the EMERGENCY level.
emergency()  : bool
Adds a log record at the EMERGENCY level.
err()  : bool
Adds a log record at the ERROR level.
error()  : bool
Adds a log record at the ERROR level.
getExceptionHandler()  : callable
getHandlers()  : array<string|int, HandlerInterface>
getLevelName()  : string
Gets the name of the logging level.
getLevels()  : array<string|int, mixed>
Gets all supported logging levels.
getName()  : string
getProcessors()  : array<string|int, callable>
info()  : bool
Adds a log record at the INFO level.
isHandling()  : bool
Checks whether the Logger has a handler that listens on the given level
log()  : bool
Adds a log record at an arbitrary level.
notice()  : bool
Adds a log record at the NOTICE level.
popHandler()  : HandlerInterface
Pops a handler from the stack
popProcessor()  : callable
Removes the processor on top of the stack and returns it.
pushHandler()  : $this
Pushes a handler on to the stack.
pushProcessor()  : $this
Adds a processor on to the stack.
reset()  : mixed
Ends a log cycle and resets all handlers and processors to their initial state.
setExceptionHandler()  : $this
Set a custom exception handler
setHandlers()  : $this
Set handlers, replacing all existing ones.
setTimezone()  : mixed
Set the timezone to be used for the timestamp of log records.
toMonologLevel()  : int
Converts PSR-3 levels to Monolog ones if necessary
useMicrosecondTimestamps()  : mixed
Control the use of microsecond resolution timestamps in the 'datetime' member of new records.
warn()  : bool
Adds a log record at the WARNING level.
warning()  : bool
Adds a log record at the WARNING level.
withName()  : static
Return a new cloned instance with the name changed
handleException()  : mixed
Delegates exception management to the custom exception handler, or throws the exception if no custom handler is set.

Constants

ALERT

Action must be taken immediately

public mixed ALERT = 550

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

API

Monolog API version

public int API = 1

This is only bumped when API breaks are done and should follow the major version of the library

CRITICAL

Critical conditions

public mixed CRITICAL = 500

Example: Application component unavailable, unexpected exception.

DEBUG

Detailed debug information

public mixed DEBUG = 100

EMERGENCY

Urgent alert.

public mixed EMERGENCY = 600

ERROR

Runtime errors

public mixed ERROR = 400

INFO

Interesting events

public mixed INFO = 200

Examples: User logs in, SQL logs.

NOTICE

Uncommon events

public mixed NOTICE = 250

WARNING

Exceptional occurrences that are not errors

public mixed WARNING = 300

Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Properties

$exceptionHandler

protected callable $exceptionHandler

$levels

Logging levels from syslog protocol defined in RFC 5424

protected static array<string|int, mixed> $levels = array(self::DEBUG => 'DEBUG', self::INFO => 'INFO', self::NOTICE => 'NOTICE', self::WARNING => 'WARNING', self::ERROR => 'ERROR', self::CRITICAL => 'CRITICAL', self::ALERT => 'ALERT', self::EMERGENCY => 'EMERGENCY')

Logging levels

$microsecondTimestamps

protected bool $microsecondTimestamps = true

$processors

Processors that will process all log records

protected array<string|int, callable> $processors

To process records of a single handler instead, add the processor on that specific handler

$timezone

protected static DateTimeZone $timezone

Methods

__construct()

public __construct(string $name[, array<string|int, HandlerInterface$handlers = array() ][, array<string|int, callable> $processors = array() ]) : mixed
Parameters
$name : string

The logging channel

$handlers : array<string|int, HandlerInterface> = array()

Optional stack of handlers, the first one in the array is called first, etc.

$processors : array<string|int, callable> = array()

Optional array of processors

addAlert()

Adds a log record at the ALERT level.

public addAlert(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addCritical()

Adds a log record at the CRITICAL level.

public addCritical(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addDebug()

Adds a log record at the DEBUG level.

public addDebug(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addEmergency()

Adds a log record at the EMERGENCY level.

public addEmergency(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addError()

Adds a log record at the ERROR level.

public addError(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addInfo()

Adds a log record at the INFO level.

public addInfo(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addNotice()

Adds a log record at the NOTICE level.

public addNotice(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addRecord()

Adds a log record.

public addRecord(int $level, string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$level : int

The logging level

$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

addWarning()

Adds a log record at the WARNING level.

public addWarning(string $message[, array<string|int, mixed> $context = array() ]) : bool
Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

alert()

Adds a log record at the ALERT level.

public alert(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

close()

Ends a log cycle and frees all resources used by handlers.

public close() : mixed

Closing a Handler means flushing all buffers and freeing any open resources/handles. Handlers that have been closed should be able to accept log records again and re-open themselves on demand, but this may not always be possible depending on implementation.

This is useful at the end of a request and will be called automatically on every handler when they get destructed.

crit()

Adds a log record at the CRITICAL level.

public crit(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

critical()

Adds a log record at the CRITICAL level.

public critical(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

debug()

Adds a log record at the DEBUG level.

public debug(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

emerg()

Adds a log record at the EMERGENCY level.

public emerg(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

emergency()

Adds a log record at the EMERGENCY level.

public emergency(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

err()

Adds a log record at the ERROR level.

public err(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

error()

Adds a log record at the ERROR level.

public error(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

getExceptionHandler()

public getExceptionHandler() : callable
Return values
callable

getLevelName()

Gets the name of the logging level.

public static getLevelName(int $level) : string
Parameters
$level : int
Return values
string

getLevels()

Gets all supported logging levels.

public static getLevels() : array<string|int, mixed>
Return values
array<string|int, mixed>

Assoc array with human-readable level names => level codes.

getName()

public getName() : string
Return values
string

getProcessors()

public getProcessors() : array<string|int, callable>
Return values
array<string|int, callable>

info()

Adds a log record at the INFO level.

public info(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

isHandling()

Checks whether the Logger has a handler that listens on the given level

public isHandling(int $level) : bool
Parameters
$level : int
Return values
bool

log()

Adds a log record at an arbitrary level.

public log(mixed $level, string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$level : mixed

The log level

$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

notice()

Adds a log record at the NOTICE level.

public notice(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

popProcessor()

Removes the processor on top of the stack and returns it.

public popProcessor() : callable
Return values
callable

pushProcessor()

Adds a processor on to the stack.

public pushProcessor(callable $callback) : $this
Parameters
$callback : callable
Return values
$this

reset()

Ends a log cycle and resets all handlers and processors to their initial state.

public reset() : mixed

Resetting a Handler or a Processor means flushing/cleaning all buffers, resetting internal state, and getting it back to a state in which it can receive log records again.

This is useful in case you want to avoid logs leaking between two requests or jobs when you have a long running process like a worker or an application server serving multiple requests in one process.

setExceptionHandler()

Set a custom exception handler

public setExceptionHandler(callable $callback) : $this
Parameters
$callback : callable
Return values
$this

setHandlers()

Set handlers, replacing all existing ones.

public setHandlers(array<string|int, HandlerInterface$handlers) : $this

If a map is passed, keys will be ignored.

Parameters
$handlers : array<string|int, HandlerInterface>
Return values
$this

setTimezone()

Set the timezone to be used for the timestamp of log records.

public static setTimezone(DateTimeZone $tz) : mixed

This is stored globally for all Logger instances

Parameters
$tz : DateTimeZone

Timezone object

toMonologLevel()

Converts PSR-3 levels to Monolog ones if necessary

public static toMonologLevel(string|int $level) : int
Parameters
$level : string|int

Level number (monolog) or name (PSR-3)

Return values
int

useMicrosecondTimestamps()

Control the use of microsecond resolution timestamps in the 'datetime' member of new records.

public useMicrosecondTimestamps(bool $micro) : mixed

Generating microsecond resolution timestamps by calling microtime(true), formatting the result via sprintf() and then parsing the resulting string via \DateTime::createFromFormat() can incur a measurable runtime overhead vs simple usage of DateTime to capture a second resolution timestamp in systems which generate a large number of log events.

Parameters
$micro : bool

True to use microtime() to create timestamps

warn()

Adds a log record at the WARNING level.

public warn(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

warning()

Adds a log record at the WARNING level.

public warning(string $message[, array<string|int, mixed> $context = array() ]) : bool

This method allows for compatibility with common interfaces.

Parameters
$message : string

The log message

$context : array<string|int, mixed> = array()

The log context

Return values
bool

Whether the record has been processed

withName()

Return a new cloned instance with the name changed

public withName(mixed $name) : static
Parameters
$name : mixed
Return values
static

handleException()

Delegates exception management to the custom exception handler, or throws the exception if no custom handler is set.

protected handleException(Exception $e, array<string|int, mixed> $record) : mixed
Parameters
$e : Exception
$record : array<string|int, mixed>

        
On this page

Search results