@@ -10,14 +10,34 @@ inspired by the Python LogBook library.
10
10
Usage
11
11
-----
12
12
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).
15
35
16
36
.. tip ::
17
37
18
38
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 .
21
41
22
42
The basic handler is the ``StreamHandler `` which writes logs in a stream
23
43
(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
29
49
action level (ERROR in the configuration provided in the standard
30
50
edition) by forwarding the messages to another handler.
31
51
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
-
45
52
Using several handlers
46
53
~~~~~~~~~~~~~~~~~~~~~~
47
54
0 commit comments