Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c788325

Browse filesBrowse files
committed
feature #3841 [Cookbook][Logging] register processor per handler and per channel (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Cookbook][Logging] register processor per handler and per channel | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #3798 Commits ------- 8a83649 register processor per handler and per channel
2 parents 136864b + 8a83649 commit c788325
Copy full SHA for c788325

File tree

Expand file treeCollapse file tree

1 file changed

+99
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+99
-2
lines changed

‎cookbook/logging/monolog.rst

Copy file name to clipboardExpand all lines: cookbook/logging/monolog.rst
+99-2Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ allows you to log the messages in several ways easily.
8080
.. code-block:: xml
8181
8282
<!-- app/config/config.xml -->
83+
<?xml version="1.0" encoding="UTF-8" ?>
8384
<container xmlns="http://symfony.com/schema/dic/services"
8485
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8586
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -180,6 +181,7 @@ easily. Your formatter must implement
180181
.. code-block:: xml
181182
182183
<!-- app/config/config.xml -->
184+
<?xml version="1.0" encoding="UTF-8" ?>
183185
<container xmlns="http://symfony.com/schema/dic/services"
184186
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
185187
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -294,6 +296,8 @@ using a processor.
294296
295297
.. code-block:: xml
296298
299+
<!-- app/config/config.xml -->
300+
<?xml version="1.0" encoding="UTF-8" ?>
297301
<container xmlns="http://symfony.com/schema/dic/services"
298302
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
299303
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -347,7 +351,100 @@ using a processor.
347351
348352
.. note::
349353

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'));
352449
353450
.. _Monolog: https://github.com/Seldaek/monolog

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.