Skip to content

Commit

Permalink
Fixed logger processor example
Browse files Browse the repository at this point in the history
  • Loading branch information
HeahDude committed Jul 27, 2017
1 parent df84f3d commit 24ddb64
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions logging/processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ using a processor.

.. code-block:: php
namespace AppBundle;
namespace AppBundle\Logger;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class SessionRequestProcessor
{
private $session;
private $token;
private $sessionId;
public function __construct(Session $session)
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
public function processRecord(array $record)
{
if (null === $this->token) {
try {
$this->token = substr($this->session->getId(), 0, 8);
} catch (\RuntimeException $e) {
$this->token = '????????';
}
$this->token .= '-' . substr(uniqid(), -8);
if (!$this->session->isStarted()) {
return $record;
}
$record['extra']['token'] = $this->token;
if (!$this->sessionId) {
$this->sessionId = substr($this->session->getId(), 0, 8) ?: '????????';
}
$record['extra']['token'] = $this->sessionId.'-'.substr(uniqid('', true), -8);
return $record;
}
Expand All @@ -59,8 +59,8 @@ using a processor.
arguments:
- "[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n"
monolog.processor.session_request:
class: AppBundle\SessionRequestProcessor
app.logger.session_request_processor:
class: AppBundle\Logger\SessionRequestProcessor
arguments: ['@session']
tags:
- { name: monolog.processor, method: processRecord }
Expand All @@ -71,7 +71,7 @@ using a processor.
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
formatter: monolog.formatter.session_request
formatter: app.logger.session_request_processor
.. code-block:: xml
Expand All @@ -92,8 +92,8 @@ using a processor.
<argument>[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%&#xA;</argument>
</service>
<service id="monolog.processor.session_request"
class="AppBundle\SessionRequestProcessor">
<service id="app.logger.session_request_processor"
class="AppBundle\Logger\SessionRequestProcessor">
<argument type="service" id="session" />
<tag name="monolog.processor" method="processRecord" />
Expand All @@ -106,23 +106,23 @@ using a processor.
type="stream"
path="%kernel.logs_dir%/%kernel.environment%.log"
level="debug"
formatter="monolog.formatter.session_request"
formatter="app.logger.session_request_processor"
/>
</monolog:config>
</container>
.. code-block:: php
// app/config/config.php
use AppBundle\SessionRequestProcessor;
use AppBundle\Logger\SessionRequestProcessor;
use Monolog\Formatter\LineFormatter;
$container
->register('monolog.formatter.session_request', LineFormatter::class)
->addArgument('[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n');
$container
->register('monolog.processor.session_request', SessionRequestProcessor::class)
->register('app.logger.session_request_processor', SessionRequestProcessor::class)
->addArgument(new Reference('session'))
->addTag('monolog.processor', array('method' => 'processRecord'));
Expand All @@ -132,7 +132,7 @@ using a processor.
'type' => 'stream',
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
'level' => 'debug',
'formatter' => 'monolog.formatter.session_request',
'formatter' => 'app.logger.session_request_processor',
),
),
));
Expand All @@ -155,8 +155,8 @@ the ``monolog.processor`` tag:
# app/config/config.yml
services:
monolog.processor.session_request:
class: AppBundle\SessionRequestProcessor
app.logger.session_request_processor:
class: AppBundle\Logger\SessionRequestProcessor
arguments: ['@session']
tags:
- { name: monolog.processor, method: processRecord, handler: main }
Expand All @@ -174,8 +174,8 @@ the ``monolog.processor`` tag:
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
<services>
<service id="monolog.processor.session_request"
class="AppBundle\SessionRequestProcessor">
<service id="app.logger.session_request_processor
class="AppBundle\Logger\SessionRequestProcessor">
<argument type="service" id="session" />
<tag name="monolog.processor" method="processRecord" handler="main" />
Expand All @@ -190,7 +190,7 @@ the ``monolog.processor`` tag:
// ...
$container
->register(
'monolog.processor.session_request',
'app.logger.session_request_processor',
SessionRequestProcessor::class
)
->addArgument(new Reference('session'))
Expand All @@ -208,8 +208,8 @@ the ``monolog.processor`` tag:
# app/config/config.yml
services:
monolog.processor.session_request:
class: AppBundle\SessionRequestProcessor
app.logger.session_request_processor:
class: AppBundle\Logger\SessionRequestProcessor
arguments: ['@session']
tags:
- { name: monolog.processor, method: processRecord, channel: main }
Expand All @@ -227,8 +227,8 @@ the ``monolog.processor`` tag:
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
<services>
<service id="monolog.processor.session_request"
class="AppBundle\SessionRequestProcessor">
<service id="app.logger.session_request_processor"
class="AppBundle\Logger\SessionRequestProcessor">
<argument type="service" id="session" />
<tag name="monolog.processor" method="processRecord" channel="main" />
Expand All @@ -242,6 +242,6 @@ the ``monolog.processor`` tag:
// ...
$container
->register('monolog.processor.session_request', SessionRequestProcessor::class)
->register('app.logger.session_request_processor', SessionRequestProcessor::class)
->addArgument(new Reference('session'))
->addTag('monolog.processor', array('method' => 'processRecord', 'channel' => 'main'));

0 comments on commit 24ddb64

Please sign in to comment.