- improved error logging vor CLI (cronjob) scripts
This commit is contained in:
@@ -597,6 +597,24 @@ class Controller {
|
||||
return $userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* print error information in CLI mode
|
||||
* @param \stdClass $error
|
||||
*/
|
||||
protected function echoErrorCLI(\stdClass $error){
|
||||
echo '[' . date('H:i:s') . '] ───────────────────────────' . PHP_EOL;
|
||||
foreach(get_object_vars($error) as $key => $value){
|
||||
$row = str_pad(' ',2 ) . str_pad($key . ':',10 );
|
||||
if($key == 'trace'){
|
||||
$value = preg_replace("/\r\n|\r|\n/", "\n" . str_pad(' ',12 ), $value);
|
||||
$row .= PHP_EOL . str_pad(' ',12 ) . $value;
|
||||
}else{
|
||||
$row .= $value;
|
||||
}
|
||||
echo $row . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onError() callback function
|
||||
* -> on AJAX request -> return JSON with error information
|
||||
@@ -631,7 +649,11 @@ class Controller {
|
||||
$f3->status($error->code);
|
||||
}
|
||||
|
||||
if($f3->get('AJAX')){
|
||||
if($f3->get('CLI')){
|
||||
$this->echoErrorCLI($error);
|
||||
// no further processing (no HTML output)
|
||||
return false;
|
||||
}elseif($f3->get('AJAX')){
|
||||
$return = (object) [];
|
||||
$return->error[] = $error;
|
||||
echo json_encode($return);
|
||||
|
||||
Reference in New Issue
Block a user