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
Table of Contents
Interfaces
- EventSubscriberInterface
- An EventSubscriber knows itself what events it is interested in.
Properties
- $bubble : bool
- $formatter : FormatterInterface|null
- $level : int
- $processors : array<string|int, callable>
- $consoleFormatterOptions : array<string|int, mixed>
- $output : mixed
- $verbosityLevelMap : array<string|int, mixed>
Methods
- __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}|array<int, array{0: string, 1?: int}>>
- 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
$bubble
protected
bool
$bubble
= true
$formatter
protected
FormatterInterface|null
$formatter
$level
protected
int
$level
= \Monolog\Logger::DEBUG
Tags
$processors
protected
array<string|int, callable>
$processors
= []
Tags
$consoleFormatterOptions
private
array<string|int, mixed>
$consoleFormatterOptions
$output
private
mixed
$output
$verbosityLevelMap
private
array<string|int, mixed>
$verbosityLevelMap
= [\Symfony\Component\Console\Output\OutputInterface::VERBOSITY_QUIET => \Monolog\Logger::ERROR, \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_NORMAL => \Monolog\Logger::WARNING, \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_VERBOSE => \Monolog\Logger::NOTICE, \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_VERY_VERBOSE => \Monolog\Logger::INFO, \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_DEBUG => \Monolog\Logger::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> = []
__destruct()
public
__destruct() : mixed
__sleep()
public
__sleep() : mixed
close()
Disables the output.
public
close() : 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.
getFormatter()
{@inheritDoc}
public
getFormatter() : FormatterInterface
Return values
FormatterInterfacegetLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Tags
Return values
intgetSubscribedEvents()
Returns an array of event names this subscriber wants to listen to.
public
static getSubscribedEvents() : array<string, string|array{0: string, 1: int}|array<int, array{0: string, 1?: int}>>
Return values
array<string, string|array{0: string, 1: int}|array<int, array{0: string, 1?: int}>>handle()
{@inheritDoc}
public
handle(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
Return values
boolhandleBatch()
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)
isHandling()
{@inheritdoc}
public
isHandling(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
Return values
boolonCommand()
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
onTerminate()
After a command has been executed, it disables the output.
public
onTerminate(ConsoleTerminateEvent $event) : mixed
Parameters
- $event : ConsoleTerminateEvent
popProcessor()
{@inheritDoc}
public
popProcessor() : callable
Return values
callablepushProcessor()
{@inheritDoc}
public
pushProcessor(callable $callback) : HandlerInterface
Parameters
- $callback : callable
Return values
HandlerInterfacereset()
public
reset() : void
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
selfsetFormatter()
{@inheritDoc}
public
setFormatter(FormatterInterface $formatter) : HandlerInterface
Parameters
- $formatter : FormatterInterface
Return values
HandlerInterfacesetLevel()
Sets minimum logging level at which this handler will be triggered.
public
setLevel(Level|LevelName|LogLevel::* $level) : self
Parameters
- $level : Level|LevelName|LogLevel::*
-
Level or level name
Return values
selfsetOutput()
Sets the console output to use for printing logs.
public
setOutput(OutputInterface $output) : mixed
Parameters
- $output : OutputInterface
getDefaultFormatter()
{@inheritdoc}
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterfaceprocessRecord()
Processes a record.
protected
processRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>resetProcessors()
protected
resetProcessors() : void
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>
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