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,7 @@ using a processor::
30
30
$this->session = $session;
31
31
}
32
32
33
+ // this method is called for each log record; optimize it to not hurt performance
33
34
public function __invoke(array $record)
34
35
{
35
36
if (!$this->session->isStarted()) {
@@ -179,6 +180,11 @@ Symfony's MonologBridge provides processors that can be registered inside your a
179
180
:class: `Symfony\\ Bridge\\ Monolog\\ Processor\\ ConsoleCommandProcessor `
180
181
Adds information about current console command.
181
182
183
+ .. seealso ::
184
+
185
+ Check out the `built-in Monolog processors `_ to learn more about how to
186
+ create these processors.
187
+
182
188
Registering Processors per Handler
183
189
----------------------------------
184
190
@@ -266,3 +272,6 @@ the ``monolog.processor`` tag:
266
272
$container
267
273
->register(SessionRequestProcessor::class)
268
274
->addTag('monolog.processor', ['channel' => 'main']);
275
+
276
+ .. _`Monolog` : https://github.com/Seldaek/monolog
277
+ .. _`built-in Monolog processors` : https://github.com/Seldaek/monolog/tree/master/src/Monolog/Processor
0 commit comments