always require a message paramter for data logging

also ensure it plays well with current log reader

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2020-01-28 13:00:13 +01:00
parent 46aaeb4561
commit e008444887
No known key found for this signature in database
GPG key ID: 7424F1874854DF23
5 changed files with 19 additions and 6 deletions

View file

@ -33,7 +33,7 @@ class LogContext {
protected $details;
public function setDescription(string $description): LogContext {
$this->details['description'] = $description;
$this->details['message'] = $description;
return $this;
}

View file

@ -162,8 +162,10 @@ class Logger {
return;
}
$details = $logContext->getDetails();
$this->flowLogger->logData(
$logContext->getDetails(),
$details['message'],
$details,
['app' => Application::APP_ID, 'level' => $context['level']]
);
}

View file

@ -340,7 +340,7 @@ class Log implements ILogger, IDataLogger {
}
}
public function logData(array $data, array $context = []): void {
public function logData(string $message, array $data, array $context = []): void {
$app = $context['app'] ?? 'no app in context';
$level = $context['level'] ?? ILogger::ERROR;
@ -350,6 +350,7 @@ class Log implements ILogger, IDataLogger {
try {
if ($level >= $minLevel) {
$data['message'] = $message;
if (!$this->logger instanceof IFileBased) {
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
}

View file

@ -80,6 +80,16 @@ abstract class LogDetails {
'userAgent',
'version'
);
if(is_array($message) && !array_key_exists('Exception', $message)) {
// Exception messages should stay as they are,
// anything else modern is split to 'message' (string) and
// data (array) fields
$shortMessage = $message['message'] ?? '(no message provided)';
$entry['data'] = $message;
$entry['message'] = $shortMessage;
}
return $entry;
}

View file

@ -28,15 +28,15 @@ namespace OCP\Log;
* Interface IDataLogger
*
* @package OCP\Log
* @since 18.0.0
* @since 18.0.1
*/
interface IDataLogger {
/**
* allows to log custom data, similar to how logException works
*
* @since 18.0.0
* @since 18.0.1
*/
public function logData(array $data, array $context = []): void;
public function logData(string $message, array $data, array $context = []): void;
}