Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzoInc committed May 30, 2019
2 parents 1bdc584 + fe2e299 commit 8d5f3be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"require": {
"php": ">=5.6.4",
"katzgrau/klogger": "^1.2.1"
"katzgrau/klogger": "^1.2.1",
"ext-json": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*",
Expand Down
31 changes: 29 additions & 2 deletions src/Logger/log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ public function __construct()
$this->logger = new Logger($path, $level, $options);
}

/**
* Getting backtrace
*
* https://www.php.net/manual/en/function.debug-backtrace.php#111355
*
* @param int $ignore ignore calls
*
* @return string
*/
protected function getBacktrace($ignore = 2)
{
$trace = '';
foreach (debug_backtrace() as $k => $v) {
if ($k < $ignore) {
continue;
}

array_walk($v['args'], function (&$item, $key) {
$item = var_export($item, true);
});

$trace .= '#' . ($k - $ignore) . ' ' . $v['file'] . '(' . $v['line'] . '): ' . (isset($v['class']) ? $v['class'] . '->' : '') . $v['function'] . '(' . implode(', ', $v['args']) . ')' . "\n";
}

return $trace;
}

/**
* @param $message
*/
Expand Down Expand Up @@ -81,14 +108,14 @@ public function warn($message)
*/
public function error($message)
{
$this->logger->error($message);
$this->logger->error($message . " - Backtrace: " . $this->getBacktrace());
}

/**
* @param $message
*/
public function critical($message)
{
$this->logger->critical($message);
$this->logger->critical($message . " - Backtrace: " . $this->getBacktrace());
}
}

0 comments on commit 8d5f3be

Please sign in to comment.