$this->run($this->argument);
} catch (\Exception $e) {
if ($logger) {
- $logger->error('Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')');
- $logger->logException($e);
+ $logger->logException($e, [
+ 'app' => 'core',
+ 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
+ ]);
}
}
}
'Line' => $exception->getLine(),
);
$exception['Trace'] = preg_replace('!(login|checkPassword)\(.*\)!', '$1(*** username and password replaced ***)', $exception['Trace']);
- $this->error('Exception: ' . json_encode($exception), $context);
+ $msg = isset($context['message']) ? $context['message'] : 'Exception';
+ $msg .= ': ' . json_encode($exception);
+ $this->error($msg, $context);
}
}
/**
* Logs an exception very detailed
+ * An additional message can we written to the log by adding it to the
+ * context.
+ *
+ * <code>
+ * $logger->logException($ex, [
+ * 'message' => 'Exception during cron job execution'
+ * ]);
+ * </code>
*
* @param \Exception $exception
* @param array $context
$logger = $this->getMockBuilder('OCP\ILogger')
->disableOriginalConstructor()
->getMock();
- $logger->expects($this->once())
- ->method('error')
- ->with('Error while running background job (class: Test\BackgroundJob\TestJob, arguments: )');
$logger->expects($this->once())
->method('logException')
->with($e);