Add message key to context of logException

This commit is contained in:
Thomas Müller 2016-01-15 13:13:27 +01:00
parent 86f08f59d6
commit f6c4b10189
4 changed files with 15 additions and 6 deletions

View File

@ -52,8 +52,10 @@ abstract class Job implements IJob {
$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) . ')'
]);
}
}
}

View File

@ -285,6 +285,8 @@ class Log implements ILogger {
'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);
}
}

View File

@ -125,6 +125,14 @@ interface ILogger {
/**
* 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

View File

@ -27,9 +27,6 @@ class Job extends \Test\TestCase {
$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);