class LogManager implements LoggerInterface mixin Logger

Traits

Constants

protected SHARED_CONTEXT_KEY

Context key for shared log context across channels.

Properties

protected array $levels

The Log levels.

from  ParsesLogConfiguration
protected array $channels

The array of resolved channels.

protected array $customCreators

The registered custom driver creators.

protected string $dateFormat

The standard date format to use when writing logs.

Methods

string
getFallbackChannelName()

Get fallback log channel name.

Level
level(array $config)

Parse the string level into a Monolog constant.

Level
actionLevel(array $config)

Parse the action level from the given configuration.

string
parseChannel(array $config)

Extract the log channel from the given configuration.

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Application $app)

Create a new Log manager instance.

LoggerInterface
build(array $config)

Build an on-demand log channel.

LoggerInterface
stack(array $channels, string|null $channel = null)

Create a new, on-demand aggregate logger instance.

LoggerInterface
channel(UnitEnum|string|null $channel = null)

Get a log channel instance.

LoggerInterface
driver(UnitEnum|string|null $driver = null)

Get a log driver instance.

LoggerInterface
get(string|null $name, array|null $config = null)

Attempt to get the log from the local cache.

LoggerInterface
createLogger(string|null $name, array|null $config = null, bool $cache = false)

Create a configured logger, optionally retaining a named channel.

tap(array $config, Logger $logger)

Apply the configured taps for the logger.

array
parseTap(string $tap)

Parse the given tap class string into a class name and arguments string.

LoggerInterface
createEmergencyLogger()

Create an emergency log handler to avoid white screens of death.

LoggerInterface
resolve(string|null $name, array $config)

Resolve the given log instance by name.

mixed
callCustomCreator(array $config)

Call a custom driver creator.

LoggerInterface
createCustomDriver(array $config)

Create a custom log driver instance.

LoggerInterface
createStackDriver(array $config)

Create an aggregate log driver instance.

LoggerInterface
createSingleDriver(array $config)

Create an instance of the single file log driver.

LoggerInterface
createDailyDriver(array $config)

Create an instance of the daily file log driver.

LoggerInterface
createMonthlyDriver(array $config)

Create an instance of the monthly file log driver.

LoggerInterface
createRotatingDriver(array $config, string $dateFormat, int $maxFiles)

Create an instance of a rotating file log driver.

LoggerInterface
createSlackDriver(array $config)

Create an instance of the Slack log driver.

LoggerInterface
createSyslogDriver(array $config)

Create an instance of the syslog log driver.

LoggerInterface
createErrorlogDriver(array $config)

Create an instance of the "error log" log driver.

LoggerInterface
createMonologDriver(array $config)

Create an instance of any handler available in Monolog.

array
prepareHandlers(array $handlers)

Prepare the handlers for usage by Monolog.

HandlerInterface
prepareHandler(HandlerInterface $handler, array $config = [])

Prepare the handler for usage by Monolog.

FormatterInterface
formatter()

Get a Monolog formatter instance.

makeContextProcessor()

Create a wrapped context log processor.

shareContext(array $context)

Share context across channels and stacks.

array
sharedContext()

The context shared across channels and stacks.

withoutContext(array|null $keys = null)

Flush the log context on all currently resolved channels.

flushSharedContext()

Flush the shared context.

array|null
configurationFor(string|null $name)

Get the log connection configuration.

string|null
getDefaultDriver()

Get the default log driver name.

void
setDefaultDriver(UnitEnum|string $name)

Set the default log driver name.

extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

void
forgetChannel(UnitEnum|string|null $driver = null)

Unset the given channel instance.

string|null
parseDriver(string|null $driver)

Parse the driver name.

array
getChannels()

Get all of the resolved log channels.

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

System is unusable.

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

Action must be taken immediately.

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

Critical conditions.

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

Runtime errors that do not require immediate action but should typically be logged and monitored.

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

Exceptional occurrences that are not errors.

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

Normal but significant events.

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

Interesting events.

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

Detailed debug information.

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

Logs with an arbitrary level.

setApplication(Application $app)

Set the application instance used by the manager.

mixed
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Details

at line 591
protected string getFallbackChannelName()

Get fallback log channel name.

Return Value

string

protected Level level(array $config)

Parse the string level into a Monolog constant.

Parameters

array $config

Return Value

Level

Exceptions

InvalidArgumentException

protected Level actionLevel(array $config)

Parse the action level from the given configuration.

Parameters

array $config

Return Value

Level

Exceptions

InvalidArgumentException

protected string parseChannel(array $config)

Extract the log channel from the given configuration.

Parameters

array $config

Return Value

string

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

at line 80
__construct(Application $app)

Create a new Log manager instance.

Parameters

Application $app

at line 88
LoggerInterface build(array $config)

Build an on-demand log channel.

Parameters

array $config

Return Value

LoggerInterface

at line 96
LoggerInterface stack(array $channels, string|null $channel = null)

Create a new, on-demand aggregate logger instance.

Parameters

array $channels
string|null $channel

Return Value

LoggerInterface

at line 118
LoggerInterface channel(UnitEnum|string|null $channel = null)

Get a log channel instance.

Parameters

UnitEnum|string|null $channel

Return Value

LoggerInterface

at line 126
LoggerInterface driver(UnitEnum|string|null $driver = null)

Get a log driver instance.

Parameters

UnitEnum|string|null $driver

Return Value

LoggerInterface

at line 138
protected LoggerInterface get(string|null $name, array|null $config = null)

Attempt to get the log from the local cache.

Parameters

string|null $name
array|null $config

Return Value

LoggerInterface

at line 150
protected LoggerInterface createLogger(string|null $name, array|null $config = null, bool $cache = false)

Create a configured logger, optionally retaining a named channel.

Parameters

string|null $name
array|null $config
bool $cache

Return Value

LoggerInterface

at line 191
protected Logger tap(array $config, Logger $logger)

Apply the configured taps for the logger.

Parameters

array $config
Logger $logger

Return Value

Logger

at line 205
protected array parseTap(string $tap)

Parse the given tap class string into a class name and arguments string.

Parameters

string $tap

Return Value

array

at line 213
protected LoggerInterface createEmergencyLogger()

Create an emergency log handler to avoid white screens of death.

Return Value

LoggerInterface

at line 233
protected LoggerInterface resolve(string|null $name, array $config)

Resolve the given log instance by name.

Parameters

string|null $name
array $config

Return Value

LoggerInterface

Exceptions

InvalidArgumentException

at line 251
protected mixed callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

mixed

at line 259
protected LoggerInterface createCustomDriver(array $config)

Create a custom log driver instance.

Parameters

array $config

Return Value

LoggerInterface

at line 269
protected LoggerInterface createStackDriver(array $config)

Create an aggregate log driver instance.

Parameters

array $config

Return Value

LoggerInterface

at line 305
protected LoggerInterface createSingleDriver(array $config)

Create an instance of the single file log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 324
protected LoggerInterface createDailyDriver(array $config)

Create an instance of the daily file log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 336
protected LoggerInterface createMonthlyDriver(array $config)

Create an instance of the monthly file log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 348
protected LoggerInterface createRotatingDriver(array $config, string $dateFormat, int $maxFiles)

Create an instance of a rotating file log driver.

Parameters

array $config
string $dateFormat
int $maxFiles

Return Value

LoggerInterface

at line 366
protected LoggerInterface createSlackDriver(array $config)

Create an instance of the Slack log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 387
protected LoggerInterface createSyslogDriver(array $config)

Create an instance of the syslog log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 401
protected LoggerInterface createErrorlogDriver(array $config)

Create an instance of the "error log" log driver.

Parameters

array $config

Return Value

LoggerInterface

at line 416
protected LoggerInterface createMonologDriver(array $config)

Create an instance of any handler available in Monolog.

Parameters

array $config

Return Value

LoggerInterface

Exceptions

InvalidArgumentException

at line 474
protected array prepareHandlers(array $handlers)

Prepare the handlers for usage by Monolog.

Parameters

array $handlers

Return Value

array

at line 486
protected HandlerInterface prepareHandler(HandlerInterface $handler, array $config = [])

Prepare the handler for usage by Monolog.

Parameters

HandlerInterface $handler
array $config

Return Value

HandlerInterface

at line 514
protected FormatterInterface formatter()

Get a Monolog formatter instance.

Return Value

FormatterInterface

at line 526
protected ResolvedContextLogProcessor makeContextProcessor()

Create a wrapped context log processor.

Wrapping in ResolvedContextLogProcessor allows createStackDriver() to filter out context processors from constituent channels regardless of how the processor was bound (class, closure, or custom callable).

at line 538
LogManager shareContext(array $context)

Share context across channels and stacks.

Parameters

array $context

Return Value

LogManager

at line 554
array sharedContext()

The context shared across channels and stacks.

Return Value

array

at line 565
LogManager withoutContext(array|null $keys = null)

Flush the log context on all currently resolved channels.

Parameters

array|null $keys

Return Value

LogManager

at line 581
LogManager flushSharedContext()

Flush the shared context.

Return Value

LogManager

at line 599
protected array|null configurationFor(string|null $name)

Get the log connection configuration.

Parameters

string|null $name

Return Value

array|null

at line 607
string|null getDefaultDriver()

Get the default log driver name.

Return Value

string|null

at line 617
void setDefaultDriver(UnitEnum|string $name)

Set the default log driver name.

Mutates process-global config; per-request use races across coroutines.

Parameters

UnitEnum|string $name

Return Value

void

at line 638
LogManager extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.

The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent channel resolution.

Parameters

string $driver
Closure $callback

Return Value

LogManager

at line 660
void forgetChannel(UnitEnum|string|null $driver = null)

Unset the given channel instance.

Mutates the singleton's channel cache; concurrent coroutines may already hold a reference to the channel and next resolution will rebuild with fresh handlers (file handles, etc.).

Parameters

UnitEnum|string|null $driver

Return Value

void

at line 677
protected string|null parseDriver(string|null $driver)

Parse the driver name.

Parameters

string|null $driver

Return Value

string|null

at line 695
array getChannels()

Get all of the resolved log channels.

Return Value

array

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

System is unusable.

Parameters

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

Return Value

void

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

Action must be taken immediately.

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

Parameters

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

Return Value

void

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

Critical conditions.

Example: Application component unavailable, unexpected exception.

Parameters

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

Return Value

void

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

Runtime errors that do not require immediate action but should typically be logged and monitored.

Parameters

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

Return Value

void

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

Exceptional occurrences that are not errors.

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

Parameters

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

Return Value

void

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

Normal but significant events.

Parameters

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

Return Value

void

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

Interesting events.

Example: User logs in, SQL logs.

Parameters

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

Return Value

void

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

Detailed debug information.

Parameters

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

Return Value

void

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

Logs with an arbitrary level.

Parameters

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

Return Value

void

at line 794
LogManager setApplication(Application $app)

Set the application instance used by the manager.

Swaps the singleton's Application reference; per-request use races across coroutines and breaks every concurrent request resolving services through this manager.

Parameters

Application $app

Return Value

LogManager

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

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed