Skip to content

Commit

Permalink
feature #3841 [Cookbook][Logging] register processor per handler and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
weaverryan committed May 13, 2014
2 parents 136864b + 8a83649 commit c788325
Showing 1 changed file with 99 additions and 2 deletions.
101 changes: 99 additions & 2 deletions cookbook/logging/monolog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ allows you to log the messages in several ways easily.
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
Expand Down Expand Up @@ -180,6 +181,7 @@ easily. Your formatter must implement
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
Expand Down Expand Up @@ -294,6 +296,8 @@ using a processor.
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
Expand Down Expand Up @@ -347,7 +351,100 @@ using a processor.
.. note::

If you use several handlers, you can also register the processor at the
handler level instead of globally.
If you use several handlers, you can also register a processor at the
handler level or at the channel level instead of registering it globally
(see the following sections).

Registering Processors per Handler
----------------------------------

You can register a processor per handler using the ``handler`` option of
the ``monolog.processor`` tag:

.. configuration-block::

.. code-block:: yaml
# app/config/config.yml
services:
monolog.processor.session_request:
class: Acme\MyBundle\SessionRequestProcessor
arguments: ["@session"]
tags:
- { name: monolog.processor, method: processRecord, handler: main }
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
>
<services>
<service id="monolog.processor.session_request" class="Acme\MyBundle\SessionRequestProcessor">
<argument type="service" id="session" />
<tag name="monolog.processor" method="processRecord" handler="main" />
</service>
</services>
</container>
.. code-block:: php
// app/config/config.php
$container
->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor')
->addArgument(new Reference('session'))
->addTag('monolog.processor', array('method' => 'processRecord', 'handler' => 'main'));
Registering Processors per Channel
----------------------------------

You can register a processor per channel using the ``channel`` option of
the ``monolog.processor`` tag:

.. configuration-block::

.. code-block:: yaml
# app/config/config.yml
services:
monolog.processor.session_request:
class: Acme\MyBundle\SessionRequestProcessor
arguments: ["@session"]
tags:
- { name: monolog.processor, method: processRecord, channel: main }
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
>
<services>
<service id="monolog.processor.session_request" class="Acme\MyBundle\SessionRequestProcessor">
<argument type="service" id="session" />
<tag name="monolog.processor" method="processRecord" channel="main" />
</service>
</services>
</container>
.. code-block:: php
// app/config/config.php
$container
->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor')
->addArgument(new Reference('session'))
->addTag('monolog.processor', array('method' => 'processRecord', 'channel' => 'main'));
.. _Monolog: https://github.com/Seldaek/monolog

0 comments on commit c788325

Please sign in to comment.