diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-01-14 10:43:50 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-01-28 10:58:57 +0100 |
commit | 46aaeb45612e20b6f460396533faf7f26ed1d6f7 (patch) | |
tree | edf3c37534c4af5d4865ddd37785139e5b2ab916 /lib/private/Log.php | |
parent | 74f1b09f3d9d350a3374a35391b79722e81533e9 (diff) | |
download | nextcloud-server-46aaeb45612e20b6f460396533faf7f26ed1d6f7.tar.gz nextcloud-server-46aaeb45612e20b6f460396533faf7f26ed1d6f7.zip |
log Flow activity
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Log.php')
-rw-r--r-- | lib/private/Log.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 916d557003f..8d51a673a46 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,28 @@ class Log implements ILogger { } } + public function logData(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) { + 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 |