3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Log\Processor
;
12 class Backtrace
implements ProcessorInterface
15 * Maximum stack level of backtrace (PHP > 5.4.0)
18 protected $traceLimit = 10;
21 * Classes within this namespace in the stack are ignored
24 protected $ignoredNamespace = 'Zend\\Log';
27 * Adds the origin of the log() call to the event extras
29 * @param array $event event data
30 * @return array event data
32 public function process(array $event)
34 $trace = $this->getBacktrace();
36 array_shift($trace); // ignore $this->getBacktrace();
37 array_shift($trace); // ignore $this->process()
40 while (isset($trace[$i]['class'])
41 && false !== strpos($trace[$i]['class'], $this->ignoredNamespace
)
47 'file' => isset($trace[$i-1]['file']) ?
$trace[$i-1]['file'] : null,
48 'line' => isset($trace[$i-1]['line']) ?
$trace[$i-1]['line'] : null,
49 'class' => isset($trace[$i]['class']) ?
$trace[$i]['class'] : null,
50 'function' => isset($trace[$i]['function']) ?
$trace[$i]['function'] : null,
54 if (isset($event['extra'])) {
55 $extra = array_merge($origin, $event['extra']);
57 $event['extra'] = $extra;
63 * Provide backtrace as slim as posible
67 protected function getBacktrace()
69 if (version_compare(PHP_VERSION
, '5.4.0') >= 0) {
70 return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS
, $this->traceLimit
);
73 if (version_compare(PHP_VERSION
, '5.3.6') >= 0) {
74 return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS
);
77 return debug_backtrace();