|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eccube\Log\Monolog\Listener; |
|
4
|
|
|
|
|
5
|
|
|
use Eccube\Log\Log; |
|
6
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; |
|
8
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
10
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
|
11
|
|
|
use Symfony\Component\HttpKernel\Event\PostResponseEvent; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
13
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* EccubeListener |
|
17
|
|
|
*/ |
|
18
|
|
|
class EccubeListener implements EventSubscriberInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
protected $log; |
|
22
|
|
|
|
|
23
|
1062 |
|
public function __construct(Log $log) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
1062 |
|
$this->log = $log; |
|
26
|
1062 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param GetResponseEvent $event |
|
30
|
|
|
*/ |
|
31
|
462 |
|
public function onKernelRequestEarly(GetResponseEvent $event) |
|
32
|
|
|
{ |
|
33
|
462 |
|
if (!$event->isMasterRequest()) { |
|
34
|
72 |
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
462 |
|
$this->log->info('INIT'); |
|
38
|
462 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param GetResponseEvent $event |
|
42
|
|
|
*/ |
|
43
|
460 |
View Code Duplication |
public function onKernelRequest(GetResponseEvent $event) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
460 |
|
if (!$event->isMasterRequest()) { |
|
46
|
72 |
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
458 |
|
$route = $this->getRoute($event->getRequest()); |
|
50
|
458 |
|
$this->log->info('PROCESS START', array($route)); |
|
51
|
458 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param FilterControllerEvent $event |
|
55
|
|
|
*/ |
|
56
|
459 |
View Code Duplication |
public function onKernelController(FilterControllerEvent $event) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
459 |
|
if (!$event->isMasterRequest()) { |
|
59
|
72 |
|
return; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
457 |
|
$route = $this->getRoute($event->getRequest()); |
|
63
|
457 |
|
$this->log->info('LOGIC START', array($route)); |
|
64
|
457 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param FilterResponseEvent $event |
|
68
|
|
|
*/ |
|
69
|
450 |
View Code Duplication |
public function onKernelResponse(FilterResponseEvent $event) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
450 |
|
if (!$event->isMasterRequest()) { |
|
72
|
72 |
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
450 |
|
$route = $this->getRoute($event->getRequest()); |
|
76
|
450 |
|
$this->log->info('LOGIC END', array($route)); |
|
77
|
450 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param PostResponseEvent $event |
|
81
|
|
|
*/ |
|
82
|
447 |
|
public function onKernelTerminate(PostResponseEvent $event) |
|
83
|
|
|
{ |
|
84
|
447 |
|
$route = $this->getRoute($event->getRequest()); |
|
85
|
447 |
|
$this->log->info('PROCESS END', array($route)); |
|
86
|
447 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param GetResponseForExceptionEvent $event |
|
90
|
|
|
*/ |
|
91
|
17 |
|
public function onKernelException(GetResponseForExceptionEvent $event) |
|
92
|
|
|
{ |
|
93
|
17 |
|
$e = $event->getException(); |
|
94
|
17 |
|
if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) { |
|
95
|
13 |
|
$this->log->info($e->getMessage(), array($e->getStatusCode())); |
|
96
|
|
|
|
|
|
|
|
|
|
97
|
13 |
|
} else { |
|
98
|
4 |
|
$message = sprintf( |
|
99
|
4 |
|
'%s: %s (uncaught exception) at %s line %s', |
|
100
|
4 |
|
get_class($e), |
|
101
|
4 |
|
$e->getMessage(), |
|
102
|
4 |
|
$e->getFile(), |
|
103
|
4 |
|
$e->getLine() |
|
104
|
4 |
|
); |
|
105
|
4 |
|
$this->log->error($message, array('exception' => $e)); |
|
106
|
|
|
} |
|
107
|
17 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* {@inheritdoc} |
|
111
|
|
|
*/ |
|
112
|
1062 |
|
public static function getSubscribedEvents() |
|
113
|
|
|
{ |
|
114
|
|
|
return array( |
|
115
|
|
|
|
|
116
|
1062 |
|
KernelEvents::REQUEST => array( |
|
117
|
|
|
// Application::initRenderingで、フロント/管理画面の判定が行われた後に実行 |
|
118
|
1062 |
|
array('onKernelRequestEarly', 500), |
|
119
|
|
|
// SecurityServiceProviderで、認証処理が完了した後に実行. |
|
120
|
1062 |
|
array('onKernelRequest', 6), |
|
121
|
1062 |
|
), |
|
122
|
1062 |
|
KernelEvents::RESPONSE => array('onKernelResponse', 0), |
|
123
|
1062 |
|
KernelEvents::CONTROLLER => array('onKernelController', 0), |
|
124
|
1062 |
|
KernelEvents::TERMINATE => array('onKernelTerminate', 0), |
|
125
|
|
|
/* |
|
126
|
|
|
* Priority -4 is used to come after those from SecurityServiceProvider (0) |
|
127
|
|
|
* but before the error handlers added with Silex\Application::error (defaults to -8) |
|
128
|
|
|
*/ |
|
129
|
1062 |
|
KernelEvents::EXCEPTION => array('onKernelException', -4), |
|
130
|
1062 |
|
); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* ルーティング名を取得する. |
|
135
|
|
|
* |
|
136
|
|
|
* @param $request |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
463 |
|
private function getRoute($request) |
|
140
|
|
|
{ |
|
141
|
463 |
|
return $request->attributes->get('_route'); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|