1
1
How to Add extra Data to Log Messages via a Processor
2
2
=====================================================
3
3
4
- Monolog allows you to process the record before logging it to add some
5
- extra data. A processor can be applied for the whole handler stack or
6
- only for a specific handler.
4
+ Monolog allows you to process every record before logging it by adding some
5
+ extra data. This is the role of a processor, which can be applied for the whole
6
+ handler stack or only for a specific handler or channel .
7
7
8
8
A processor is a callable receiving the record as its first argument.
9
9
Processors are configured using the ``monolog.processor `` DIC tag. See the
@@ -30,6 +30,8 @@ using a processor::
30
30
$this->session = $session;
31
31
}
32
32
33
+ // This method is called for each log record and process it.
34
+ // Keep it optimized process, to not introduce any overhead.
33
35
public function __invoke(array $record)
34
36
{
35
37
if (!$this->session->isStarted()) {
@@ -184,6 +186,9 @@ Symfony's MonologBridge provides processors that can be registered inside your a
184
186
The ``RouteProcessor `` and the ``ConsoleCommandProcessor `` were introduced
185
187
in Symfony 4.3.
186
188
189
+ Monolog _ also have built in processors ready to use inside your application.
190
+ Read the librairy documentation to learn more.
191
+
187
192
Registering Processors per Handler
188
193
----------------------------------
189
194
@@ -271,3 +276,5 @@ the ``monolog.processor`` tag:
271
276
$container
272
277
->register(SessionRequestProcessor::class)
273
278
->addTag('monolog.processor', ['channel' => 'main']);
279
+
280
+ .. _Monolog : https://github.com/Seldaek/monolog
0 commit comments