Skip to content

Commit b07aadc

Browse files
committed
minor #19607 [Logger] [Monolog] Mention #[WithMonologChannel] (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Logger] [Monolog] Mention `#[WithMonologChannel]` Fix #19568 Commits ------- c2b9771 [Monolog] Mention `#[WithMonologChannel]`
2 parents f018c09 + c2b9771 commit b07aadc

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
@@ -103,5 +103,6 @@ whitelist:
103103
- '.. versionadded:: 0.2' # MercureBundle
104104
- '.. versionadded:: 3.6' # MonologBundle
105105
- '.. versionadded:: 3.8' # MonologBundle
106+
- '.. versionadded:: 3.5' # Monolog
106107
- '.. _`a feature to test applications using Mercure`: https://github.com/symfony/panther#creating-isolated-browsers-to-test-apps-using-mercure-or-websocket'
107108
- '.. 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)