Skip to content

[Logging] Mention #[AsMonologProcessor] #17790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions logging/processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down