diff --git a/logging/processors.rst b/logging/processors.rst index 76cb497fd70..8e67634ccd0 100644 --- a/logging/processors.rst +++ b/logging/processors.rst @@ -164,6 +164,30 @@ If you use several handlers, you can also register a processor at the handler level or at the channel level instead of registering it globally (see the following sections). +When registering a new processor, instead of adding the tag manually in your +configuration files, you can take full advantage of the ``#[AsMonologProcessor]`` +attribute by using it one the processor class:: + + // src/Logger/SessionRequestProcessor.php + namespace App\Logger; + + use Monolog\Attribute\AsMonologProcessor; + // ... + + #[AsMonologProcessor] + class SessionRequestProcessor + { + // ... + } + +The ``#[AsMonologProcessor]`` attribute takes 3 optional arguments: + +* ``channel``: the logging channel the processor should be pushed to +* ``handler``: the handler the processor should be pushed to +* ``method``: the method that processes the records (if the attribute is used + at the class level). Indeed, the attribute can also be used directly + on a class method. + Symfony's MonologBridge provides processors that can be registered inside your application. :class:`Symfony\\Bridge\\Monolog\\Processor\\DebugProcessor`