|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Monolog package. |
|
|
5 |
* |
|
|
6 |
* (c) Jordi Boggiano <j.boggiano@seld.be> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Monolog\Processor; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Injects line/file:class/function where the log message came from |
|
|
16 |
* |
|
|
17 |
* Warning: This only works if the handler processes the logs directly. |
|
|
18 |
* If you put the processor on a handler that is behind a FingersCrossedHandler |
|
|
19 |
* for example, the processor will only be called once the trigger level is reached, |
|
|
20 |
* and all the log records will have the same file/line/.. data from the call that |
|
|
21 |
* triggered the FingersCrossedHandler. |
|
|
22 |
* |
|
|
23 |
* @author Jordi Boggiano <j.boggiano@seld.be> |
|
|
24 |
*/ |
|
|
25 |
class IntrospectionProcessor |
|
|
26 |
{ |
|
|
27 |
/** |
|
|
28 |
* @param array $record |
|
|
29 |
* @return array |
|
|
30 |
*/ |
|
|
31 |
public function __invoke(array $record) |
|
|
32 |
{ |
|
|
33 |
$trace = debug_backtrace(); |
|
|
34 |
|
|
|
35 |
// skip first since it's always the current method |
|
|
36 |
array_shift($trace); |
|
|
37 |
// the call_user_func call is also skipped |
|
|
38 |
array_shift($trace); |
|
|
39 |
|
|
|
40 |
$i = 0; |
|
|
41 |
while (isset($trace[$i]['class']) && false !== strpos($trace[$i]['class'], 'Monolog\\')) { |
|
|
42 |
$i++; |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
// we should have the call source now |
|
|
46 |
$record['extra'] = array_merge( |
|
|
47 |
$record['extra'], |
|
|
48 |
array( |
|
|
49 |
'file' => isset($trace[$i-1]['file']) ? $trace[$i-1]['file'] : null, |
|
|
50 |
'line' => isset($trace[$i-1]['line']) ? $trace[$i-1]['line'] : null, |
|
|
51 |
'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, |
|
|
52 |
'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, |
|
|
53 |
) |
|
|
54 |
); |
|
|
55 |
|
|
|
56 |
return $record; |
|
|
57 |
} |
|
|
58 |
} |