Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed logger processor example#8226

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
xabbuh merged 1 commit intosymfony:2.7fromHeahDude:fix/log-processing
Sep 3, 2017
Merged
Changes fromall 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
62 changes: 31 additions & 31 deletionslogging/processors.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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:
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Should be an FQCN from 3.3

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>
<serviceid="monolog.processor.session_request"
class="AppBundle\SessionRequestProcessor">
<serviceid="app.logger.session_request_processor"
class="AppBundle\Logger\SessionRequestProcessor">
<argumenttype="service"id="session" />
<tagname="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'))
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

'session' should beSessionInterface::class from 3.3

->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>
<serviceid="monolog.processor.session_request"
class="AppBundle\SessionRequestProcessor">
<serviceid="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>
<serviceid="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'));

[8]ページ先頭

©2009-2025 Movatter.jp