class Logger implements LoggerInterface (View source)

Traits

Properties

protected LoggerInterface $logger

The underlying logger implementation.

protected Dispatcher|null $dispatcher

The event dispatcher instance.

protected array $context

Any context to be added to logs.

Methods

$this|TWhenReturnType
when($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

void
__construct(LoggerInterface $logger, Dispatcher $dispatcher = null)

Create a new log writer instance.

void
emergency(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an emergency message to the logs.

void
alert(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an alert message to the logs.

void
critical(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a critical message to the logs.

void
error(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an error message to the logs.

void
warning(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a warning message to the logs.

void
notice(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a notice to the logs.

void
info(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an informational message to the logs.

void
debug(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a debug message to the logs.

void
log(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a message to the logs.

void
write(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Dynamically pass log calls into the writer.

void
writeLog(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context)

Write a message to the log.

$this
withContext(array $context = [])

Add context to all future logs.

$this
withoutContext()

Flush the existing context array.

void
listen(Closure $callback)

Register a new callback handler for when a log event is triggered.

void
fireLogEvent(string $level, string $message, array $context = [])

Fires a log event.

string
formatMessage(Arrayable|Jsonable|Stringable|array|string $message)

Format the parameters for the logger.

LoggerInterface
getLogger()

Get the underlying logger implementation.

getEventDispatcher()

Get the event dispatcher instance.

void
setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

mixed
__call(string $method, array $parameters)

Dynamically proxy method calls to the underlying logger.

Details

$this|TWhenReturnType when($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable $callback
callable $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable $callback
callable $default

Return Value

$this|TUnlessReturnType

void __construct(LoggerInterface $logger, Dispatcher $dispatcher = null)

Create a new log writer instance.

Parameters

LoggerInterface $logger
Dispatcher $dispatcher

Return Value

void

void emergency(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an emergency message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void alert(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an alert message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void critical(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a critical message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void error(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an error message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void warning(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a warning message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void notice(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a notice to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void info(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log an informational message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void debug(Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a debug message to the logs.

Parameters

Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void log(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Log a message to the logs.

Parameters

string $level
Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

void write(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context = [])

Dynamically pass log calls into the writer.

Parameters

string $level
Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

protected void writeLog(string $level, Arrayable|Jsonable|Stringable|array|string $message, array $context)

Write a message to the log.

Parameters

string $level
Arrayable|Jsonable|Stringable|array|string $message
array $context

Return Value

void

$this withContext(array $context = [])

Add context to all future logs.

Parameters

array $context

Return Value

$this

$this withoutContext()

Flush the existing context array.

Return Value

$this

void listen(Closure $callback)

Register a new callback handler for when a log event is triggered.

Parameters

Closure $callback

Return Value

void

Exceptions

RuntimeException

protected void fireLogEvent(string $level, string $message, array $context = [])

Fires a log event.

Parameters

string $level
string $message
array $context

Return Value

void

protected string formatMessage(Arrayable|Jsonable|Stringable|array|string $message)

Format the parameters for the logger.

Parameters

Arrayable|Jsonable|Stringable|array|string $message

Return Value

string

LoggerInterface getLogger()

Get the underlying logger implementation.

Return Value

LoggerInterface

Dispatcher getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher

void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters

Dispatcher $dispatcher

Return Value

void

mixed __call(string $method, array $parameters)

Dynamically proxy method calls to the underlying logger.

Parameters

string $method
array $parameters

Return Value

mixed