W3cubDocs

/Symfony 4.1

ConsoleHandler

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::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.

Methods

__construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = array())
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.

write(array $record)

{@inheritdoc}

getDefaultFormatter()

{@inheritdoc}

Details

__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)

isHandling(array $record)

{@inheritdoc}

Parameters

array $record

handle(array $record)

{@inheritdoc}

Parameters

array $record

setOutput(OutputInterface $output)

Sets the console output to use for printing logs.

Parameters

OutputInterface $output

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.

Parameters

ConsoleCommandEvent $event

onTerminate(ConsoleTerminateEvent $event)

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

Parameters

ConsoleTerminateEvent $event

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

protected write(array $record)

{@inheritdoc}

Parameters

array $record

protected getDefaultFormatter()

{@inheritdoc}

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bridge/Monolog/Handler/ConsoleHandler.html