Skip to content

Commit fe0571a

Browse files
committed
Merge branch '2.3' into 2.4
2 parents 112d16b + 109c67d commit fe0571a

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

cookbook/logging/channels_handlers.rst

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,62 @@ Creating your own Channel
8181
-------------------------
8282

8383
You can change the channel monolog logs to one service at a time. This is done
84-
by tagging your service with ``monolog.logger`` and specifying which channel
85-
the service should log to. By doing this, the logger that is injected into
86-
that service is preconfigured to use the channel you've specified.
84+
either via the :ref:`configuration <cookbook-monolog-channels-config>` below
85+
or by tagging your service with :ref:`monolog.logger<dic_tags-monolog>` and
86+
specifying which channel the service should log to. With the tag, the logger
87+
that is injected into that service is preconfigured to use the channel you've
88+
specified.
8789

88-
For more information - including a full example - read ":ref:`dic_tags-monolog`"
89-
in the Dependency Injection Tags reference section.
90+
.. _cookbook-monolog-channels-config:
91+
92+
Configure Additional Channels without Tagged Services
93+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
.. versionadded:: 2.3
96+
This feature was introduced to the MonologBundle in version 2.4. This
97+
version is compatible with Symfony 2.3, but only MonologBundle 2.3 is
98+
installed by default. To use this feature, upgrade your bundle manually.
99+
100+
With MonologBundle 2.4 you can configure additional channels without the
101+
need to tag your services:
102+
103+
.. configuration-block::
104+
105+
.. code-block:: yaml
106+
107+
# app/config/config.yml
108+
monolog:
109+
channels: ["foo", "bar"]
110+
111+
.. code-block:: xml
112+
113+
<!-- app/config/config.xml -->
114+
<container xmlns="http://symfony.com/schema/dic/services"
115+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
116+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
117+
xsi:schemaLocation="http://symfony.com/schema/dic/services
118+
http://symfony.com/schema/dic/services/services-1.0.xsd
119+
http://symfony.com/schema/dic/monolog
120+
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
121+
>
122+
<monolog:config>
123+
<monolog:channel>foo</monolog:channel>
124+
<monolog:channel>bar</monolog:channel>
125+
</monolog:config>
126+
</container>
127+
128+
.. code-block:: php
129+
130+
// app/config/config.php
131+
$container->loadFromExtension('monolog', array(
132+
'channels' => array(
133+
'foo',
134+
'bar',
135+
),
136+
));
137+
138+
With this, you can now send log messages to the ``foo`` channel by using
139+
the automatically registered logger service ``monolog.logger.foo``.
90140

91141
Learn more from the Cookbook
92142
----------------------------

reference/dic_tags.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,12 @@ channel when injecting the logger in a service.
663663
$definition->addTag('monolog.logger', array('channel' => 'acme'));
664664
$container->register('my_service', $definition);
665665
666+
.. tip::
667+
668+
If you use MonologBundle 2.4 or higher, you can configure custom channels
669+
in the configuration and retrieve the corresponding logger service from
670+
the service container directly (see :ref:`cookbook-monolog-channels-config`).
671+
666672
.. _dic_tags-monolog-processor:
667673
668674
monolog.processor

0 commit comments

Comments
 (0)