Skip to content

Commit c2b9771

Browse files
[Monolog] Mention #[WithMonologChannel]
1 parent a7d98b0 commit c2b9771

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.doctor-rst.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,6 @@ whitelist:
104104
- '.. versionadded:: 0.2' # MercureBundle
105105
- '.. versionadded:: 3.6' # MonologBundle
106106
- '.. versionadded:: 3.8' # MonologBundle
107+
- '.. versionadded:: 3.5' # Monolog
107108
- '.. _`a feature to test applications using Mercure`: https://github.com/symfony/panther#creating-isolated-browsers-to-test-apps-using-mercure-or-websocket'
108109
- '.. End to End Tests (E2E)'

logging/channels_handlers.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,35 @@ change your constructor like this:
194194
$this->logger = $fooBarLogger;
195195
}
196196
197+
Configure Logger Channels with Attributes
198+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199+
200+
Starting from `Monolog`_ 3.5 you can also configure the logger channel
201+
by using the ``#[WithMonologChannel]`` attribute directly on your service
202+
class::
203+
204+
// src/Service/MyFixtureService.php
205+
namespace App\Service;
206+
207+
use Monolog\Attribute\WithMonologChannel;
208+
use Psr\Log\LoggerInterface;
209+
use Symfony\Bridge\Monolog\Logger;
210+
211+
#[WithMonologChannel('fixtures')]
212+
class MyFixtureService
213+
{
214+
public function __construct(LoggerInterface $logger)
215+
{
216+
// ...
217+
}
218+
}
219+
220+
This way you can avoid declaring your service manually to use a specific
221+
channel.
222+
223+
.. versionadded:: 3.5
224+
225+
The ``#[WithMonologChannel]`` attribute was introduced in Monolog 3.5.0.
226+
197227
.. _`MonologBundle`: https://github.com/symfony/monolog-bundle
228+
.. _`Monolog`: https://github.com/Seldaek/monolog

0 commit comments

Comments
 (0)