diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-02-10 15:09:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 15:09:51 +0100 |
commit | 1b07dcf35c6984e4c27edd14045b6265aaf20b90 (patch) | |
tree | 1f1a830778781bb16639d4d6b875a2edf8c724b2 /lib/private | |
parent | a71957f2b93d5bdc03dfeda82b3f234850cc9823 (diff) | |
parent | e00844488709552febdc07c19bed4c7ceb52a98d (diff) | |
download | nextcloud-server-1b07dcf35c6984e4c27edd14045b6265aaf20b90.tar.gz nextcloud-server-1b07dcf35c6984e4c27edd14045b6265aaf20b90.zip |
Merge pull request #18904 from nextcloud/enh/noid/flow-logging
Log Flow activity
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Log.php | 26 | ||||
-rw-r--r-- | lib/private/Log/LogDetails.php | 10 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 916d557003f..d288e724179 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -36,6 +36,7 @@ declare(strict_types=1); namespace OC; +use OCP\Log\IDataLogger; use function array_merge; use InterfaSys\LogNormalizer\Normalizer; @@ -54,7 +55,7 @@ use OCP\Support\CrashReport\IRegistry; * * MonoLog is an example implementing this interface. */ -class Log implements ILogger { +class Log implements ILogger, IDataLogger { /** @var IWriter */ private $logger; @@ -339,6 +340,29 @@ class Log implements ILogger { } } + public function logData(string $message, array $data, array $context = []): void { + $app = $context['app'] ?? 'no app in context'; + $level = $context['level'] ?? ILogger::ERROR; + + $minLevel = $this->getLogLevel($context); + + array_walk($context, [$this->normalizer, 'format']); + + try { + if ($level >= $minLevel) { + $data['message'] = $message; + if (!$this->logger instanceof IFileBased) { + $data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); + } + $this->writeLog($app, $data, $level); + } + + $context['level'] = $level; + } catch (\Throwable $e) { + // make sure we dont hard crash if logging fails + } + } + /** * @param string $app * @param string|array $entry diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php index 2eea17ad73d..b1dc6e4311b 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; } |