summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-02-11 16:03:11 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-02-11 16:16:34 +0100
commitd45692ee9651f5dc32bee15d518a9c0cf5c5c2b9 (patch)
treeb63930e5895f407813befe0a992d23a8e83c51f5 /lib
parent5babad4f6fb983709e7851bb5cea4bc0d2c7fe4c (diff)
downloadnextcloud-server-d45692ee9651f5dc32bee15d518a9c0cf5c5c2b9.tar.gz
nextcloud-server-d45692ee9651f5dc32bee15d518a9c0cf5c5c2b9.zip
Migrate custom loggers to PSR
This will help phase out the deprecated ILogger interface. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Log/LogFactory.php8
-rw-r--r--lib/private/Log/PsrLoggerAdapter.php12
-rw-r--r--lib/public/Log/ILogFactory.php10
3 files changed, 27 insertions, 3 deletions
diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php
index 7064fe324e6..6e6ded3758b 100644
--- a/lib/private/Log/LogFactory.php
+++ b/lib/private/Log/LogFactory.php
@@ -31,6 +31,7 @@ use OCP\ILogger;
use OCP\IServerContainer;
use OCP\Log\ILogFactory;
use OCP\Log\IWriter;
+use Psr\Log\LoggerInterface;
class LogFactory implements ILogFactory {
/** @var IServerContainer */
@@ -70,6 +71,13 @@ class LogFactory implements ILogFactory {
return new Log($log, $this->systemConfig);
}
+ public function getCustomPsrLogger(string $path): LoggerInterface {
+ $log = $this->buildLogFile($path);
+ return new PsrLoggerAdapter(
+ new Log($log, $this->systemConfig)
+ );
+ }
+
protected function buildLogFile(string $logFile = ''):File {
$defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log';
if ($logFile === '') {
diff --git a/lib/private/Log/PsrLoggerAdapter.php b/lib/private/Log/PsrLoggerAdapter.php
index c488441da41..8cd64bfe903 100644
--- a/lib/private/Log/PsrLoggerAdapter.php
+++ b/lib/private/Log/PsrLoggerAdapter.php
@@ -26,19 +26,21 @@ declare(strict_types=1);
namespace OC\Log;
+use OC\Log;
use OCP\ILogger;
+use OCP\Log\IDataLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Throwable;
use function array_key_exists;
use function array_merge;
-final class PsrLoggerAdapter implements LoggerInterface {
+final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
- /** @var ILogger */
+ /** @var Log */
private $logger;
- public function __construct(ILogger $logger) {
+ public function __construct(Log $logger) {
$this->logger = $logger;
}
@@ -260,4 +262,8 @@ final class PsrLoggerAdapter implements LoggerInterface {
$this->logger->log($level, $message, $context);
}
}
+
+ public function logData(string $message, array $data, array $context = []): void {
+ $this->logger->logData($message, $data, $context);
+ }
}
diff --git a/lib/public/Log/ILogFactory.php b/lib/public/Log/ILogFactory.php
index a2cb02e8759..54aa6456156 100644
--- a/lib/public/Log/ILogFactory.php
+++ b/lib/public/Log/ILogFactory.php
@@ -25,6 +25,7 @@
namespace OCP\Log;
use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* Interface ILogFactory
@@ -43,6 +44,15 @@ interface ILogFactory {
* @param string $path
* @return ILogger
* @since 14.0.0
+ * @deprecated use \OCP\Log\ILogFactory::getCustomPsrLogger
+ * @see \OCP\Log\ILogFactory::getCustomPsrLogger
*/
public function getCustomLogger(string $path): ILogger;
+
+ /**
+ * @param string $path
+ * @return LoggerInterface
+ * @since 22.0.0
+ */
+ public function getCustomPsrLogger(string $path): LoggerInterface;
}