@@ -14,9 +14,9 @@ the channel).
14
14
15
15
.. note ::
16
16
17
- Each channel corresponds to a logger service (``monolog.logger.XXX ``)
18
- in the container (use the ``php bin/console debug:container monolog `` command
19
- to see a full list) and those are injected into different services .
17
+ Each channel corresponds to a different logger service (``monolog.logger.XXX ``)
18
+ Use the ``php bin/console debug:container monolog `` command to see a full
19
+ list of services and learn :ref: ` how to autowire monolog channels < monolog-autowire-channels >` .
20
20
21
21
.. _logging-channel-handler :
22
22
@@ -172,3 +172,23 @@ Symfony automatically registers one service per channel (in this example, the
172
172
channel ``foo `` creates a service called ``monolog.logger.foo ``). In order to
173
173
inject this service into others, you must update the service configuration to
174
174
:ref: `choose the specific service to inject <services-wire-specific-service >`.
175
+
176
+ .. _monolog-autowire-channels :
177
+
178
+ How to Autowire Logger Channels
179
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
+
181
+ Starting from `MonologBundle `_ 3.5 you can autowire different Monolog channels
182
+ by type-hinting your service arguments with the following syntax:
183
+ ``Psr\Log\LoggerInterface $<channel>Logger ``. For example, to inject the service
184
+ related to the ``app `` logger channel use this:
185
+
186
+ .. code-block :: diff
187
+
188
+ - public function __construct(LoggerInterface $logger)
189
+ + public function __construct(LoggerInterface $appLogger)
190
+ {
191
+ $this->logger = $appLogger;
192
+ }
193
+
194
+ .. _`MonologBundle` : https://github.com/symfony/monolog-bundle
0 commit comments