|
4 | 4 | How to Configure Monolog to Display Console Messages
|
5 | 5 | ====================================================
|
6 | 6 |
|
7 |
| -It is possible to use the console to print messages for a certain :ref:`verbosity-levels` |
| 7 | +.. versionadded:: 2.3 |
| 8 | + This feature was introduced to the MonologBundle in version 2.4, which |
| 9 | + was first packaged with Symfony at version 2.4 (but compatible with Symfony 2.3). |
| 10 | + |
| 11 | +It is possible to use the console to print messages for certain :ref:`verbosity-levels` |
8 | 12 | using the :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
|
9 | 13 | instance that is passed when a command gets executed.
|
10 | 14 |
|
@@ -39,15 +43,18 @@ The example above could then be rewritten as::
|
39 | 43 |
|
40 | 44 | protected function execute(InputInterface $input, OutputInterface $output)
|
41 | 45 | {
|
| 46 | + // assuming the Command extends ContainerAwareCommand... |
| 47 | + $logger = $this->getContainer()->get('logger'); |
42 | 48 | $logger->debug('Some info');
|
43 | 49 |
|
44 | 50 | $logger->notice('Some more info');
|
45 | 51 | }
|
46 | 52 |
|
47 |
| -These messages will get displayed on the console, timestamped, colored |
48 |
| -depending on the log level and error logs are written to the error output |
49 |
| -(php://stderr). There is no need to conditionally handle the verbosity |
50 |
| -settings anymore. |
| 53 | +Depending on the verbosity level that the command is run in and the user's |
| 54 | +configuration (see below), these messages may or may not be displayed to |
| 55 | +the console. If they are displayed, they are timestamped and colored appropriately. |
| 56 | +Additionally, error logs are written to the error output (php://stderr). |
| 57 | +There is no need to conditionally handle the verbosity settings anymore. |
51 | 58 |
|
52 | 59 | The Monolog console handler is enabled in the Monolog configuration. This is
|
53 | 60 | the default in Symfony Standard Edition 2.4 too.
|
|
0 commit comments