Skip to content

[Logger] [Processor] additional info on processor #11825

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
Sep 26, 2019
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
13 changes: 10 additions & 3 deletions logging/processors.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
How to Add extra Data to Log Messages via a Processor
=====================================================

Monolog allows you to process the record before logging it to add some
extra data. A processor can be applied for the whole handler stack or
only for a specific handler.
Monolog allows you to process every record before logging it by adding some
extra data. This is the role of a processor, which can be applied for the whole
handler stack or only for a specific handler or channel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


A processor is a callable receiving the record as its first argument.
Processors are configured using the ``monolog.processor`` DIC tag. See the
Expand All @@ -30,6 +30,8 @@ using a processor::
$this->session = $session;
}

// This method is called for each log record and process it.
// Keep it optimized process, to not introduce any overhead.
public function __invoke(array $record)
{
if (!$this->session->isStarted()) {
Expand Down Expand Up @@ -184,6 +186,9 @@ Symfony's MonologBridge provides processors that can be registered inside your a
The ``RouteProcessor`` and the ``ConsoleCommandProcessor`` were introduced
in Symfony 4.3.

Monolog_ also have built in processors ready to use inside your application.
Read the librairy documentation to learn more.

Registering Processors per Handler
----------------------------------

Expand Down Expand Up @@ -271,3 +276,5 @@ the ``monolog.processor`` tag:
$container
->register(SessionRequestProcessor::class)
->addTag('monolog.processor', ['channel' => 'main']);

.. _Monolog: https://github.com/Seldaek/monolog