|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eccube\Log\Monolog\Processor; |
|
4
|
|
|
|
|
5
|
|
|
use Monolog\Logger; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* IntrospectionProcessor拡張クラス |
|
9
|
|
|
* |
|
10
|
|
|
* @package Eccube\Log\Monolog\Processor |
|
11
|
|
|
*/ |
|
12
|
|
|
class IntrospectionProcessor |
|
13
|
|
|
{ |
|
14
|
|
|
private $level; |
|
15
|
|
|
|
|
16
|
|
|
protected $skipClassesPartials; |
|
17
|
|
|
|
|
18
|
|
|
protected $skipStackFramesCount; |
|
19
|
|
|
|
|
20
|
|
|
protected $skipFunctions = array( |
|
21
|
|
|
'call_user_func', |
|
22
|
|
|
'call_user_func_array', |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array(), array $skipFunctions = array(), $skipStackFramesCount = 0) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$this->level = Logger::toMonologLevel($level); |
|
28
|
|
|
$this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials); |
|
29
|
|
|
$this->skipFunctions = array_merge($this->skipFunctions, $skipFunctions); |
|
30
|
|
|
$this->skipStackFramesCount = $skipStackFramesCount; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param array $record |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __invoke(array $record) |
|
38
|
|
|
{ |
|
39
|
|
|
// return if the level is not high enough |
|
40
|
|
|
if ($record['level'] < $this->level) { |
|
41
|
|
|
return $record; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
45
|
|
|
|
|
46
|
|
|
// skip first since it's always the current method |
|
47
|
|
|
array_shift($trace); |
|
48
|
|
|
// the call_user_func call is also skipped |
|
49
|
|
|
array_shift($trace); |
|
50
|
|
|
|
|
51
|
|
|
$i = 0; |
|
52
|
|
|
|
|
53
|
|
|
while ($this->isTraceClassOrSkippedFunction($trace, $i)) { |
|
54
|
|
|
if (isset($trace[$i]['class'])) { |
|
55
|
|
|
foreach ($this->skipClassesPartials as $part) { |
|
56
|
|
|
if (strpos($trace[$i]['class'], $part) !== false) { |
|
57
|
|
|
$i++; |
|
58
|
|
|
continue 2; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} elseif (in_array($trace[$i]['function'], $this->skipFunctions)) { |
|
62
|
|
|
$i++; |
|
63
|
|
|
continue; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
break; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$i += $this->skipStackFramesCount; |
|
70
|
|
|
|
|
71
|
|
|
// we should have the call source now |
|
72
|
|
|
$record['extra'] = array_merge( |
|
73
|
|
|
$record['extra'], |
|
74
|
|
|
array( |
|
75
|
|
|
'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null, |
|
76
|
|
|
'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, |
|
77
|
|
|
'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, |
|
78
|
|
|
'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, |
|
79
|
|
|
) |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
return $record; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function isTraceClassOrSkippedFunction(array $trace, $index) |
|
86
|
|
|
{ |
|
87
|
|
|
if (!isset($trace[$index])) { |
|
88
|
|
|
return false; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|