Documentation

ConsoleHandler extends AbstractProcessingHandler
in package
implements EventSubscriberInterface

Writes logs to the console output depending on its verbosity setting.

It is disabled by default and gets activated as soon as a command is executed. Instead of listening to the console events, the output can also be set manually.

The minimum logging level at which this handler will be triggered depends on the verbosity setting of the console output. The default mapping is:

  • OutputInterface::VERBOSITY_NORMAL will show all WARNING and higher logs
  • OutputInterface::VERBOSITY_VERBOSE (-v) will show all NOTICE and higher logs
  • OutputInterface::VERBOSITY_VERY_VERBOSE (-vv) will show all INFO and higher logs
  • OutputInterface::VERBOSITY_DEBUG (-vvv) will show all DEBUG and higher logs, i.e. all logs

This mapping can be customized with the $verbosityLevelMap constructor parameter.

Tags
author

Tobias Schultze http://tobion.de

Interfaces, Classes and Traits

EventSubscriberInterface
An EventSubscriber knows itself what events it is interested in.

Table of Contents

$bubble  : bool
$formatter  : FormatterInterface|null
$level  : int
$processors  : array<string|int, callable>
$consoleFormatterOptions  : mixed
$output  : mixed
$verbosityLevelMap  : mixed
__construct()  : mixed
__destruct()  : mixed
__sleep()  : mixed
close()  : void
Disables the output.
getBubble()  : bool
Gets the bubbling behavior.
getFormatter()  : FormatterInterface
{@inheritDoc}
getLevel()  : int
Gets minimum logging level at which this handler will be triggered.
getSubscribedEvents()  : array<string, string|array{0: string, 1: int}|list>
Returns an array of event names this subscriber wants to listen to.
handle()  : bool
{@inheritDoc}
handleBatch()  : void
Handles a set of records at once.
isHandling()  : bool
{@inheritdoc}
onCommand()  : mixed
Before a command is executed, the handler gets activated and the console output is set in order to know where to write the logs.
onTerminate()  : mixed
After a command has been executed, it disables the output.
popProcessor()  : callable
{@inheritDoc}
pushProcessor()  : HandlerInterface
{@inheritDoc}
reset()  : void
setBubble()  : self
Sets the bubbling behavior.
setFormatter()  : HandlerInterface
{@inheritDoc}
setLevel()  : self
Sets minimum logging level at which this handler will be triggered.
setOutput()  : mixed
Sets the console output to use for printing logs.
getDefaultFormatter()  : FormatterInterface
{@inheritdoc}
processRecord()  : array<string|int, mixed>
Processes a record.
resetProcessors()  : void
write()  : void
Writes the record down to the log of the implementing handler
updateLevel()  : bool
Updates the logging level based on the verbosity setting of the console output.

Properties

$level

protected int $level = MonologLogger::DEBUG
Tags
phpstan-var

Level

$processors

protected array<string|int, callable> $processors = []
Tags
phpstan-var

array<ProcessorInterface|callable(Record): Record>

$verbosityLevelMap

private mixed $verbosityLevelMap = [SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_QUIET => MonologLogger::ERROR, SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_NORMAL => MonologLogger::WARNING, SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_VERBOSE => MonologLogger::NOTICE, SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_VERY_VERBOSE => MonologLogger::INFO, SymfonyComponentConsoleOutputOutputInterface::VERBOSITY_DEBUG => MonologLogger::DEBUG]

Methods

__construct()

public __construct([OutputInterface|null $output = null ][, bool $bubble = true ][, array<string|int, mixed> $verbosityLevelMap = [] ][, array<string|int, mixed> $consoleFormatterOptions = [] ]) : mixed
Parameters
$output : OutputInterface|null = null

The console output to use (the handler remains disabled when passing null until the output is set, e.g. by using console events)

$bubble : bool = true

Whether the messages that are handled can bubble up the stack

$verbosityLevelMap : array<string|int, mixed> = []

Array that maps the OutputInterface verbosity to a minimum logging level (leave empty to use the default mapping)

$consoleFormatterOptions : array<string|int, mixed> = []
Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__sleep()

public __sleep() : mixed
Return values
mixed

close()

Disables the output.

public close() : void
Return values
void

getBubble()

Gets the bubbling behavior.

public getBubble() : bool
Return values
bool

true means that this handler allows bubbling. false means that bubbling is not permitted.

getLevel()

Gets minimum logging level at which this handler will be triggered.

public getLevel() : int
Tags
phpstan-return

Level

Return values
int

getSubscribedEvents()

Returns an array of event names this subscriber wants to listen to.

public static getSubscribedEvents() : array<string, string|array{0: string, 1: int}|list>
Return values
array<string, string|array{0: string, 1: int}|list>

handle()

{@inheritDoc}

public handle(array<string|int, mixed> $record) : bool
Parameters
$record : array<string|int, mixed>
Return values
bool

handleBatch()

Handles a set of records at once.

public handleBatch(array<string|int, mixed> $records) : void
Parameters
$records : array<string|int, mixed>

The records to handle (an array of record arrays)

Return values
void

isHandling()

{@inheritdoc}

public isHandling(array<string|int, mixed> $record) : bool
Parameters
$record : array<string|int, mixed>
Return values
bool

onCommand()

Before a command is executed, the handler gets activated and the console output is set in order to know where to write the logs.

public onCommand(ConsoleCommandEvent $event) : mixed
Parameters
$event : ConsoleCommandEvent
Return values
mixed

setBubble()

Sets the bubbling behavior.

public setBubble(bool $bubble) : self
Parameters
$bubble : bool

true means that this handler allows bubbling. false means that bubbling is not permitted.

Return values
self

setLevel()

Sets minimum logging level at which this handler will be triggered.

public setLevel(Level|LevelName|\Psr\Log\LogLevel::* $level) : self
Parameters
$level : Level|LevelName|\Psr\Log\LogLevel::*

Level or level name

Return values
self

processRecord()

Processes a record.

protected processRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
$record : array<string|int, mixed>
Tags
phpstan-param

Record $record

phpstan-return

Record

Return values
array<string|int, mixed>

write()

Writes the record down to the log of the implementing handler

protected write(array<string|int, mixed> $record) : void
Parameters
$record : array<string|int, mixed>
Return values
void

updateLevel()

Updates the logging level based on the verbosity setting of the console output.

private updateLevel() : bool
Return values
bool

Whether the handler is enabled and verbosity is not set to quiet

Search results