Skip to content

Commit cc59ca7

Browse files
committed
minor #10125 Use callable classes for custom Monolog processors (jaikdean)
This PR was merged into the 2.8 branch. Discussion ---------- Use callable classes for custom Monolog processors The built-in Monolog processors all use callable classes with an `__invoke()` method, whereas the Symfony documentation uses a `processRecord()` method. Using `__invoke()` provides consistency with the standard processors and also removes the need to specify the method name in the service configuration. Commits ------- 6f1a0f3 Use callable classes for custom Monolog processors
2 parents c7b9cf1 + 6f1a0f3 commit cc59ca7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

logging/processors.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using a processor::
3030
$this->session = $session;
3131
}
3232

33-
public function processRecord(array $record)
33+
public function __invoke(array $record)
3434
{
3535
if (!$this->session->isStarted()) {
3636
return $record;
@@ -61,7 +61,7 @@ using a processor::
6161
class: AppBundle\Logger\SessionRequestProcessor
6262
arguments: ['@session']
6363
tags:
64-
- { name: monolog.processor, method: processRecord }
64+
- { name: monolog.processor }
6565
6666
monolog:
6767
handlers:
@@ -94,7 +94,7 @@ using a processor::
9494
class="AppBundle\Logger\SessionRequestProcessor">
9595
9696
<argument type="service" id="session" />
97-
<tag name="monolog.processor" method="processRecord" />
97+
<tag name="monolog.processor" />
9898
</service>
9999
</services>
100100
@@ -122,7 +122,7 @@ using a processor::
122122
$container
123123
->register('app.logger.session_request_processor', SessionRequestProcessor::class)
124124
->addArgument(new Reference('session'))
125-
->addTag('monolog.processor', array('method' => 'processRecord'));
125+
->addTag('monolog.processor');
126126
127127
$container->loadFromExtension('monolog', array(
128128
'handlers' => array(
@@ -157,7 +157,7 @@ the ``monolog.processor`` tag:
157157
class: AppBundle\Logger\SessionRequestProcessor
158158
arguments: ['@session']
159159
tags:
160-
- { name: monolog.processor, method: processRecord, handler: main }
160+
- { name: monolog.processor, handler: main }
161161
162162
.. code-block:: xml
163163
@@ -176,7 +176,7 @@ the ``monolog.processor`` tag:
176176
class="AppBundle\Logger\SessionRequestProcessor">
177177
178178
<argument type="service" id="session" />
179-
<tag name="monolog.processor" method="processRecord" handler="main" />
179+
<tag name="monolog.processor" handler="main" />
180180
</service>
181181
</services>
182182
</container>
@@ -192,7 +192,7 @@ the ``monolog.processor`` tag:
192192
SessionRequestProcessor::class
193193
)
194194
->addArgument(new Reference('session'))
195-
->addTag('monolog.processor', array('method' => 'processRecord', 'handler' => 'main'));
195+
->addTag('monolog.processor', array('handler' => 'main'));
196196
197197
Registering Processors per Channel
198198
----------------------------------
@@ -210,7 +210,7 @@ the ``monolog.processor`` tag:
210210
class: AppBundle\Logger\SessionRequestProcessor
211211
arguments: ['@session']
212212
tags:
213-
- { name: monolog.processor, method: processRecord, channel: main }
213+
- { name: monolog.processor, channel: main }
214214
215215
.. code-block:: xml
216216
@@ -229,7 +229,7 @@ the ``monolog.processor`` tag:
229229
class="AppBundle\Logger\SessionRequestProcessor">
230230
231231
<argument type="service" id="session" />
232-
<tag name="monolog.processor" method="processRecord" channel="main" />
232+
<tag name="monolog.processor" channel="main" />
233233
</service>
234234
</services>
235235
</container>
@@ -242,4 +242,4 @@ the ``monolog.processor`` tag:
242242
$container
243243
->register('app.logger.session_request_processor', SessionRequestProcessor::class)
244244
->addArgument(new Reference('session'))
245-
->addTag('monolog.processor', array('method' => 'processRecord', 'channel' => 'main'));
245+
->addTag('monolog.processor', array('channel' => 'main'));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy