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
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
$bubble
protected
bool
$bubble
= true
$formatter
protected
FormatterInterface|null
$formatter
$level
protected
int
$level
= MonologLogger::DEBUG
Tags
$processors
protected
array<string|int, callable>
$processors
= []
Tags
$consoleFormatterOptions
private
mixed
$consoleFormatterOptions
$output
private
mixed
$output
$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.
getFormatter()
{@inheritDoc}
public
getFormatter() : FormatterInterface
Return values
FormatterInterface —getLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Tags
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}|listhandle()
{@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 —onTerminate()
After a command has been executed, it disables the output.
public
onTerminate(ConsoleTerminateEvent $event) : mixed
Parameters
- $event : ConsoleTerminateEvent
Return values
mixed —popProcessor()
{@inheritDoc}
public
popProcessor() : callable
Return values
callable —pushProcessor()
{@inheritDoc}
public
pushProcessor(callable $callback) : HandlerInterface
Parameters
- $callback : callable
Return values
HandlerInterface —reset()
public
reset() : void
Return values
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
self —setFormatter()
{@inheritDoc}
public
setFormatter(FormatterInterface $formatter) : HandlerInterface
Parameters
- $formatter : FormatterInterface
Return values
HandlerInterface —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 —setOutput()
Sets the console output to use for printing logs.
public
setOutput(OutputInterface $output) : mixed
Parameters
- $output : OutputInterface
Return values
mixed —getDefaultFormatter()
{@inheritdoc}
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterface —processRecord()
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
Return values
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>
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