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