@@ -80,6 +80,7 @@ allows you to log the messages in several ways easily.
80
80
.. code-block :: xml
81
81
82
82
<!-- app/config/config.xml -->
83
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
83
84
<container xmlns =" http://symfony.com/schema/dic/services"
84
85
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
85
86
xmlns : monolog =" http://symfony.com/schema/dic/monolog"
@@ -180,6 +181,7 @@ easily. Your formatter must implement
180
181
.. code-block :: xml
181
182
182
183
<!-- app/config/config.xml -->
184
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
183
185
<container xmlns =" http://symfony.com/schema/dic/services"
184
186
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
185
187
xmlns : monolog =" http://symfony.com/schema/dic/monolog"
@@ -294,6 +296,8 @@ using a processor.
294
296
295
297
.. code-block :: xml
296
298
299
+ <!-- app/config/config.xml -->
300
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
297
301
<container xmlns =" http://symfony.com/schema/dic/services"
298
302
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
299
303
xmlns : monolog =" http://symfony.com/schema/dic/monolog"
@@ -347,7 +351,100 @@ using a processor.
347
351
348
352
.. note ::
349
353
350
- If you use several handlers, you can also register the processor at the
351
- handler level instead of globally.
354
+ If you use several handlers, you can also register a processor at the
355
+ handler level or at the channel level instead of registering it globally
356
+ (see the following sections).
357
+
358
+ Registering Processors per Handler
359
+ ----------------------------------
360
+
361
+ You can register a processor per handler using the ``handler `` option of
362
+ the ``monolog.processor `` tag:
363
+
364
+ .. configuration-block ::
365
+
366
+ .. code-block :: yaml
367
+
368
+ # app/config/config.yml
369
+ services :
370
+ monolog.processor.session_request :
371
+ class : Acme\MyBundle\SessionRequestProcessor
372
+ arguments : ["@session"]
373
+ tags :
374
+ - { name: monolog.processor, method: processRecord, handler: main }
375
+
376
+ .. code-block :: xml
377
+
378
+ <!-- app/config/config.xml -->
379
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
380
+ <container xmlns =" http://symfony.com/schema/dic/services"
381
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
382
+ xmlns : monolog =" http://symfony.com/schema/dic/monolog"
383
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
384
+ http://symfony.com/schema/dic/services/services-1.0.xsd
385
+ http://symfony.com/schema/dic/monolog
386
+ http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
387
+ >
388
+ <services >
389
+ <service id =" monolog.processor.session_request" class =" Acme\MyBundle\SessionRequestProcessor" >
390
+ <argument type =" service" id =" session" />
391
+ <tag name =" monolog.processor" method =" processRecord" handler =" main" />
392
+ </service >
393
+ </services >
394
+ </container >
395
+
396
+ .. code-block :: php
397
+
398
+ // app/config/config.php
399
+ $container
400
+ ->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor')
401
+ ->addArgument(new Reference('session'))
402
+ ->addTag('monolog.processor', array('method' => 'processRecord', 'handler' => 'main'));
403
+
404
+ Registering Processors per Channel
405
+ ----------------------------------
406
+
407
+ You can register a processor per channel using the ``channel `` option of
408
+ the ``monolog.processor `` tag:
409
+
410
+ .. configuration-block ::
411
+
412
+ .. code-block :: yaml
413
+
414
+ # app/config/config.yml
415
+ services :
416
+ monolog.processor.session_request :
417
+ class : Acme\MyBundle\SessionRequestProcessor
418
+ arguments : ["@session"]
419
+ tags :
420
+ - { name: monolog.processor, method: processRecord, channel: main }
421
+
422
+ .. code-block :: xml
423
+
424
+ <!-- app/config/config.xml -->
425
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
426
+ <container xmlns =" http://symfony.com/schema/dic/services"
427
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
428
+ xmlns : monolog =" http://symfony.com/schema/dic/monolog"
429
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
430
+ http://symfony.com/schema/dic/services/services-1.0.xsd
431
+ http://symfony.com/schema/dic/monolog
432
+ http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
433
+ >
434
+ <services >
435
+ <service id =" monolog.processor.session_request" class =" Acme\MyBundle\SessionRequestProcessor" >
436
+ <argument type =" service" id =" session" />
437
+ <tag name =" monolog.processor" method =" processRecord" channel =" main" />
438
+ </service >
439
+ </services >
440
+ </container >
441
+
442
+ .. code-block :: php
443
+
444
+ // app/config/config.php
445
+ $container
446
+ ->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor')
447
+ ->addArgument(new Reference('session'))
448
+ ->addTag('monolog.processor', array('method' => 'processRecord', 'channel' => 'main'));
352
449
353
450
.. _Monolog : https://github.com/Seldaek/monolog
0 commit comments