From e00844488709552febdc07c19bed4c7ceb52a98d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 28 Jan 2020 13:00:13 +0100 Subject: [PATCH] always require a message paramter for data logging also ensure it plays well with current log reader Signed-off-by: Arthur Schiwon --- apps/workflowengine/lib/Helper/LogContext.php | 2 +- apps/workflowengine/lib/Service/Logger.php | 4 +++- lib/private/Log.php | 3 ++- lib/private/Log/LogDetails.php | 10 ++++++++++ lib/public/Log/IDataLogger.php | 6 +++--- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/workflowengine/lib/Helper/LogContext.php b/apps/workflowengine/lib/Helper/LogContext.php index 786aa7cf85..548e872207 100644 --- a/apps/workflowengine/lib/Helper/LogContext.php +++ b/apps/workflowengine/lib/Helper/LogContext.php @@ -33,7 +33,7 @@ class LogContext { protected $details; public function setDescription(string $description): LogContext { - $this->details['description'] = $description; + $this->details['message'] = $description; return $this; } diff --git a/apps/workflowengine/lib/Service/Logger.php b/apps/workflowengine/lib/Service/Logger.php index 0bf09ed8a7..8b90e6fa15 100644 --- a/apps/workflowengine/lib/Service/Logger.php +++ b/apps/workflowengine/lib/Service/Logger.php @@ -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']] ); } diff --git a/lib/private/Log.php b/lib/private/Log.php index 8d51a673a4..d288e72417 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -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); } diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php index 2eea17ad73..b1dc6e4311 100644 --- a/lib/private/Log/LogDetails.php +++ b/lib/private/Log/LogDetails.php @@ -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; } diff --git a/lib/public/Log/IDataLogger.php b/lib/public/Log/IDataLogger.php index 895ba43f5c..b5d3aa3075 100644 --- a/lib/public/Log/IDataLogger.php +++ b/lib/public/Log/IDataLogger.php @@ -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; }