summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2020-01-14 10:43:50 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2020-01-28 10:58:57 +0100
commit46aaeb45612e20b6f460396533faf7f26ed1d6f7 (patch)
treeedf3c37534c4af5d4865ddd37785139e5b2ab916 /lib
parent74f1b09f3d9d350a3374a35391b79722e81533e9 (diff)
downloadnextcloud-server-46aaeb45612e20b6f460396533faf7f26ed1d6f7.tar.gz
nextcloud-server-46aaeb45612e20b6f460396533faf7f26ed1d6f7.zip
log Flow activity
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Log.php25
-rw-r--r--lib/public/Log/IDataLogger.php42
4 files changed, 68 insertions, 1 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 5edd4f2e1a3..d66039ae1fd 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -367,6 +367,7 @@ return array(
'OCP\\Lock\\LockedException' => $baseDir . '/lib/public/Lock/LockedException.php',
'OCP\\Lock\\ManuallyLockedException' => $baseDir . '/lib/public/Lock/ManuallyLockedException.php',
'OCP\\Lockdown\\ILockdownManager' => $baseDir . '/lib/public/Lockdown/ILockdownManager.php',
+ 'OCP\\Log\\IDataLogger' => $baseDir . '/lib/public/Log/IDataLogger.php',
'OCP\\Log\\IFileBased' => $baseDir . '/lib/public/Log/IFileBased.php',
'OCP\\Log\\ILogFactory' => $baseDir . '/lib/public/Log/ILogFactory.php',
'OCP\\Log\\IWriter' => $baseDir . '/lib/public/Log/IWriter.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index f81dbd7e16d..0a65eae24bb 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -396,6 +396,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Lock\\LockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/LockedException.php',
'OCP\\Lock\\ManuallyLockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/ManuallyLockedException.php',
'OCP\\Lockdown\\ILockdownManager' => __DIR__ . '/../../..' . '/lib/public/Lockdown/ILockdownManager.php',
+ 'OCP\\Log\\IDataLogger' => __DIR__ . '/../../..' . '/lib/public/Log/IDataLogger.php',
'OCP\\Log\\IFileBased' => __DIR__ . '/../../..' . '/lib/public/Log/IFileBased.php',
'OCP\\Log\\ILogFactory' => __DIR__ . '/../../..' . '/lib/public/Log/ILogFactory.php',
'OCP\\Log\\IWriter' => __DIR__ . '/../../..' . '/lib/public/Log/IWriter.php',
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
diff --git a/lib/public/Log/IDataLogger.php b/lib/public/Log/IDataLogger.php
new file mode 100644
index 00000000000..895ba43f5ca
--- /dev/null
+++ b/lib/public/Log/IDataLogger.php
@@ -0,0 +1,42 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\Log;
+
+/**
+ * Interface IDataLogger
+ *
+ * @package OCP\Log
+ * @since 18.0.0
+ */
+interface IDataLogger {
+
+ /**
+ * allows to log custom data, similar to how logException works
+ *
+ * @since 18.0.0
+ */
+ public function logData(array $data, array $context = []): void;
+
+}