class ConsoleHandler extends AbstractProcessingHandler 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::VERBOSITYNORMAL will show all WARNING and higher logs - OutputInterface::VERBOSITYVERBOSE (-v) will show all NOTICE and higher logs - OutputInterface::VERBOSITYVERYVERBOSE (-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.

Methods

__construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = array())

No description

isHandling(array $record)

{@inheritdoc}

handle(array $record)

{@inheritdoc}

setOutput(OutputInterface $output)

Sets the console output to use for printing logs.

close()

Disables the output.

onCommand(ConsoleCommandEvent $event)

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(ConsoleTerminateEvent $event)

After a command has been executed, it disables the output.

static array
getSubscribedEvents()

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

Details

at line line 61
__construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = array())

Parameters

OutputInterface $output The console output to use (the handler remains disabled when passing null until the output is set, e.g. by using console events)
bool $bubble Whether the messages that are handled can bubble up the stack
array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging level (leave empty to use the default mapping)

at line line 74
isHandling(array $record)

{@inheritdoc}

Parameters

array $record

at line line 82
handle(array $record)

{@inheritdoc}

Parameters

array $record

at line line 92
setOutput(OutputInterface $output)

Sets the console output to use for printing logs.

Parameters

OutputInterface $output

at line line 100
close()

Disables the output.

at line line 111
onCommand(ConsoleCommandEvent $event)

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

Parameters

ConsoleCommandEvent $event

at line line 124
onTerminate(ConsoleTerminateEvent $event)

After a command has been executed, it disables the output.

Parameters

ConsoleTerminateEvent $event

at line line 132
static array getSubscribedEvents()

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

The array keys are event names and the value can be:

  • The method name to call (priority defaults to 0)
  • An array composed of the method name to call and the priority
  • An array of arrays composed of the method names to call and respective priorities, or 0 if unset

For instance:

  • array('eventName' => 'methodName')
  • array('eventName' => array('methodName', $priority))
  • array('eventName' => array(array('methodName1', $priority), array('methodName2')))

Return Value

array The event names to listen to