Skip to content

Commit 01d45e4

Browse files
committed
Merge pull request #2154 from symfony/monolog-reorg
[#2151] Reorganizing part of the monolog cookbook to put usage first
2 parents ee3fd33 + 523c837 commit 01d45e4

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

cookbook/logging/monolog.rst

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,34 @@ inspired by the Python LogBook library.
1010
Usage
1111
-----
1212

13-
In Monolog each logger defines a logging channel. Each channel has a
14-
stack of handlers to write the logs (the handlers can be shared).
13+
To log a message simply get the logger service from the container in
14+
your controller::
15+
16+
public function indexAction()
17+
{
18+
$logger = $this->get('logger');
19+
$logger->info('I just got the logger');
20+
$logger->err('An error occurred');
21+
22+
// ...
23+
}
24+
25+
The ``logger`` service has different methods for different the logging levels.
26+
See :class:`Symfony\\Component\\HttpKernel\\Log\\LoggerInterface` for details
27+
on which methods are available.
28+
29+
Handlers and Channels: Writing logs to different Locations
30+
----------------------------------------------------------
31+
32+
In Monolog each logger defines a logging channel, which organizes your log
33+
messages into different "categories". Then, each channel has a stack of handlers
34+
to write the logs (the handlers can be shared).
1535

1636
.. tip::
1737

1838
When injecting the logger in a service you can
19-
:ref:`use a custom channel<dic_tags-monolog>` to see easily which
20-
part of the application logged the message.
39+
:ref:`use a custom channel<dic_tags-monolog>` control which "channel"
40+
the logger will log to.
2141

2242
The basic handler is the ``StreamHandler`` which writes logs in a stream
2343
(by default in the ``app/logs/prod.log`` in the prod environment and
@@ -29,19 +49,6 @@ messages in a buffer and to log them only if a message reaches the
2949
action level (ERROR in the configuration provided in the standard
3050
edition) by forwarding the messages to another handler.
3151

32-
To log a message simply get the logger service from the container in
33-
your controller::
34-
35-
$logger = $this->get('logger');
36-
$logger->info('I just got the logger');
37-
$logger->err('An error occurred');
38-
39-
.. tip::
40-
41-
Using only the methods of the
42-
:class:`Symfony\\Component\\HttpKernel\\Log\\LoggerInterface` interface
43-
allows to change the logger implementation without changing your code.
44-
4552
Using several handlers
4653
~~~~~~~~~~~~~~~~~~~~~~
4754

0 commit comments

Comments
 (0)