Skip to content

Instantly share code, notes, and snippets.

@picasso250
Created September 13, 2013 03:07
Show Gist options
  • Save picasso250/6546398 to your computer and use it in GitHub Desktop.
Save picasso250/6546398 to your computer and use it in GitHub Desktop.
<?php
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) {
$msg = "$errno $errstr in $errfile:$errline ";
$trace = debug_backtrace();
array_shift($trace);
$trace = array_map(function ($e) {
$function = $e['function'];
if (isset($e['class'])) {
$function = $e['class'].$e['type'].$function;
}
$args = array_map(function ($e) {
if (is_scalar($e)) {
return var_export($e, true);
} elseif (is_object($e)) {
return get_class($e);
} else {
return gettype($e);
}
}, $e['args']);
$args = implode(', ', $args);
return "$e[file]:$e[line] $function($args)";
}, $trace);
$msg .= '[ '.implode(' <-- ', $trace).' ]';
LoggerFactory::$root = __DIR__.'/';
$logger = LoggerFactory::getLogger('PHP-Job');
$logger->error($msg);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment