@@ -18,14 +18,14 @@ using a processor.
18
18
19
19
.. code-block :: php
20
20
21
- namespace AppBundle;
21
+ namespace AppBundle\Logger ;
22
22
23
23
use Symfony\Component\HttpFoundation\Session\SessionInterface;
24
24
25
25
class SessionRequestProcessor
26
26
{
27
27
private $session;
28
- private $token ;
28
+ private $sessionId ;
29
29
30
30
public function __construct(SessionInterface $session)
31
31
{
@@ -34,15 +34,15 @@ using a processor.
34
34
35
35
public function processRecord(array $record)
36
36
{
37
- if (null === $this->token) {
38
- try {
39
- $this->token = substr($this->session->getId(), 0, 8);
40
- } catch (\RuntimeException $e) {
41
- $this->token = '????????';
42
- }
43
- $this->token .= '-' . substr(uniqid(), -8);
37
+ if (!$this->session->isStarted()) {
38
+ return $record;
44
39
}
45
- $record['extra']['token'] = $this->token;
40
+
41
+ if (!$this->sessionId) {
42
+ $this->sessionId = substr($this->session->getId(), 0, 8) ?: '????????';
43
+ }
44
+
45
+ $record['extra']['token'] = $this->sessionId.'-'.substr(uniqid('', true), -8);
46
46
47
47
return $record;
48
48
}
@@ -62,7 +62,7 @@ information:
62
62
arguments :
63
63
- " [%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n "
64
64
65
- AppBundle\SessionRequestProcessor :
65
+ AppBundle\Logger\ SessionRequestProcessor :
66
66
autowire : true
67
67
tags :
68
68
- { name: monolog.processor, method: processRecord }
@@ -86,7 +86,7 @@ information:
86
86
<argument >[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%
 </argument >
87
87
</service >
88
88
89
- <service id =" AppBundle\SessionRequestProcessor" autowire =" true" >
89
+ <service id =" AppBundle\Logger\ SessionRequestProcessor" autowire =" true" >
90
90
<tag name =" monolog.processor" method =" processRecord" />
91
91
</service >
92
92
</services >
@@ -95,7 +95,7 @@ information:
95
95
.. code-block :: php
96
96
97
97
// app/config/services.php
98
- use AppBundle\SessionRequestProcessor;
98
+ use AppBundle\Logger\ SessionRequestProcessor;
99
99
use Monolog\Formatter\LineFormatter;
100
100
101
101
$container
@@ -139,7 +139,7 @@ Finally, set the formatter to be used on whatever handler you want:
139
139
type =" stream"
140
140
path =" %kernel.logs_dir%/%kernel.environment%.log"
141
141
level =" debug"
142
- formatter =" monolog.formatter.session_request "
142
+ formatter =" app.logger.session_request_processor "
143
143
/>
144
144
</monolog : config >
145
145
</container >
@@ -153,7 +153,7 @@ Finally, set the formatter to be used on whatever handler you want:
153
153
'type' => 'stream',
154
154
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
155
155
'level' => 'debug',
156
- 'formatter' => 'monolog.formatter.session_request ',
156
+ 'formatter' => 'app.logger.session_request_processor ',
157
157
),
158
158
),
159
159
));
@@ -174,7 +174,7 @@ the ``monolog.processor`` tag:
174
174
175
175
# app/config/config.yml
176
176
services :
177
- AppBundle\SessionRequestProcessor :
177
+ AppBundle\Logger\ SessionRequestProcessor :
178
178
autowire : true
179
179
tags :
180
180
- { name: monolog.processor, method: processRecord, handler: main }
@@ -192,7 +192,7 @@ the ``monolog.processor`` tag:
192
192
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" >
193
193
194
194
<services >
195
- <service id =" AppBundle\SessionRequestProcessor" autowire =" true" >
195
+ <service id =" AppBundle\Logger\ SessionRequestProcessor" autowire =" true" >
196
196
<tag name =" monolog.processor" method =" processRecord" handler =" main" />
197
197
</service >
198
198
</services >
@@ -219,7 +219,7 @@ the ``monolog.processor`` tag:
219
219
220
220
# app/config/config.yml
221
221
services :
222
- AppBundle\SessionRequestProcessor :
222
+ AppBundle\Logger\ SessionRequestProcessor :
223
223
autowire : true
224
224
tags :
225
225
- { name: monolog.processor, method: processRecord, channel: main }
@@ -237,7 +237,7 @@ the ``monolog.processor`` tag:
237
237
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" >
238
238
239
239
<services >
240
- <service id =" AppBundle\SessionRequestProcessor" autowire =" true" >
240
+ <service id =" AppBundle\Logger\ SessionRequestProcessor" autowire =" true" >
241
241
<tag name =" monolog.processor" method =" processRecord" channel =" main" />
242
242
</service >
243
243
</services >
0 commit comments