class Logger implements LoggerInterface

Traits

Constants

protected CONTEXT_KEY_PREFIX

The CoroutineContext key prefix for per-channel logger context.

Properties

static protected int $nextFamilyId

The next worker-unique logger family identifier.

protected string $stateKey

The coroutine-local key for this logger channel's context.

Methods

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

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

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

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

__construct(LoggerInterface $logger, Dispatcher|null $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.

withName(string $name)

Return a named variant of the logger.

withContext(array $context = [])

Add context to all future logs.

withoutContext(array|null $keys = null)

Flush the log context on all currently resolved channels.

array
getContext()

Get the existing context array.

state()

Get the state for this logger family in the current coroutine.

void
listen(Closure $callback)

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

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

Fire a log event.

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

Format the parameters for the logger.

LoggerInterface
getLogger()

Get the underlying logger implementation.

Dispatcher|null
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

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 48
__construct(LoggerInterface $logger, Dispatcher|null $dispatcher = null)

Create a new log writer instance.

Parameters

LoggerInterface $logger
Dispatcher|null $dispatcher

at line 64
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

at line 72
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

at line 80
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

at line 88
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

at line 96
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

at line 104
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

at line 112
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

at line 120
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

at line 130
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

at line 138
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

at line 146
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

at line 185
Logger withName(string $name)

Return a named variant of the logger.

Parameters

string $name

Return Value

Logger

Exceptions

RuntimeException

at line 202
Logger withContext(array $context = [])

Add context to all future logs.

Parameters

array $context

Return Value

Logger

at line 216
Logger withoutContext(array|null $keys = null)

Flush the log context on all currently resolved channels.

Parameters

array|null $keys

Return Value

Logger

at line 234
array getContext()

Get the existing context array.

Return Value

array

at line 244
protected LoggerState state()

Get the state for this logger family in the current coroutine.

Return Value

LoggerState

at line 260
void listen(Closure $callback)

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

Boot-only. Registers a listener on the worker-global event dispatcher; per-request registration persists and affects subsequent requests.

Parameters

Closure $callback

Return Value

void

Exceptions

RuntimeException

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

Fire a log event.

Parameters

string $level
string $message
array $context

Return Value

void

at line 295
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

at line 308
LoggerInterface getLogger()

Get the underlying logger implementation.

Return Value

LoggerInterface

at line 316
Dispatcher|null getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher|null

at line 327
void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Boot or tests only. Persists on the cached logger for the worker lifetime; per-request use races across coroutines.

Parameters

Dispatcher $dispatcher

Return Value

void

at line 339
mixed __call(string $method, array $parameters)

Dynamically proxy method calls to the underlying logger.

Parameters

string $method
array $parameters

Return Value

mixed