Skip to content

Commit d2c61a5

Browse files
committed
Merge pull request #3205 from xabbuh/issue-2862-configure-channels
add documentation for configuring additional monolog channels
2 parents eb0e925 + 05e713b commit d2c61a5

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

cookbook/logging/channels_handlers.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,57 @@ that service is preconfigured to use the channel you've specified.
8888
For more information - including a full example - read ":ref:`dic_tags-monolog`"
8989
in the Dependency Injection Tags reference section.
9090

91+
.. _cookbook-monolog-channels-config:
92+
93+
Configure Additional Channels without Tagged Services
94+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95+
96+
.. versionadded:: 2.3
97+
Since Symfony 2.3 you can install MonologBundle 2.4 to be able to configure
98+
additional channels in the configuration.
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 automically registered logger service ``monolog.logger.foo``.
140+
141+
91142
Learn more from the Cookbook
92143
----------------------------
93144

reference/dic_tags.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,12 @@ channel when injecting the logger in a service.
649649
$definition->addTag('monolog.logger', array('channel' => 'acme'));
650650
$container->register('my_service', $definition);
651651
652+
.. tip::
653+
If you use MonologBundle in version 2.4 or above, you are able to configure
654+
your custom channels in the application configuration and retrieve the
655+
corresponding logger service from the service container directly (see
656+
:ref:`cookbook-monolog-channels-config`).
657+
652658
.. _dic_tags-monolog-processor:
653659
654660
monolog.processor

0 commit comments

Comments
 (0)