Skip to content

Commit d094c8d

Browse files
committed
minor symfony#17790 [Logging] Mention #[AsMonologProcessor] (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Logging] Mention `#[AsMonologProcessor]` Fixes symfony#16818 Commits ------- c53ad31 [Logging] Mention `#[AsMonologProcessor]`
2 parents a671edf + c53ad31 commit d094c8d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

logging/processors.rst

+24
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,30 @@ If you use several handlers, you can also register a processor at the
164164
handler level or at the channel level instead of registering it globally
165165
(see the following sections).
166166

167+
When registering a new processor, instead of adding the tag manually in your
168+
configuration files, you can take full advantage of the ``#[AsMonologProcessor]``
169+
attribute by using it one the processor class::
170+
171+
// src/Logger/SessionRequestProcessor.php
172+
namespace App\Logger;
173+
174+
use Monolog\Attribute\AsMonologProcessor;
175+
// ...
176+
177+
#[AsMonologProcessor]
178+
class SessionRequestProcessor
179+
{
180+
// ...
181+
}
182+
183+
The ``#[AsMonologProcessor]`` attribute takes 3 optional arguments:
184+
185+
* ``channel``: the logging channel the processor should be pushed to
186+
* ``handler``: the handler the processor should be pushed to
187+
* ``method``: the method that processes the records (if the attribute is used
188+
at the class level). Indeed, the attribute can also be used directly
189+
on a class method.
190+
167191
Symfony's MonologBridge provides processors that can be registered inside your application.
168192

169193
:class:`Symfony\\Bridge\\Monolog\\Processor\\DebugProcessor`

0 commit comments

Comments
 (0)