]> git.mxchange.org Git - friendica.git/commitdiff
Create LegacyLoggerFactory
authorArt4 <art4@wlabs.de>
Fri, 10 Jan 2025 21:58:21 +0000 (21:58 +0000)
committerArt4 <art4@wlabs.de>
Fri, 10 Jan 2025 21:58:21 +0000 (21:58 +0000)
src/Core/Logger/Factory/LegacyLoggerFactory.php [new file with mode: 0644]
src/Core/Logger/Factory/LoggerFactory.php [new file with mode: 0644]
tests/Unit/Core/Logger/Factory/LegacyLoggerFactoryTest.php [new file with mode: 0644]

diff --git a/src/Core/Logger/Factory/LegacyLoggerFactory.php b/src/Core/Logger/Factory/LegacyLoggerFactory.php
new file mode 100644 (file)
index 0000000..4210312
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Core\Logger\Factory;
+
+use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
+use Psr\Log\NullLogger;
+
+/**
+ * Manager for the core logging instances
+ */
+final class LegacyLoggerFactory implements LoggerFactory
+{
+       /**
+        * Creates and returns a PSR-3 Logger instance.
+        *
+        * Calling this method multiple times with the same parameters SHOULD return the same object.
+        *
+        * @param \Psr\Log\LogLevel::* $logLevel The log level
+        * @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
+        */
+       public function createLogger(string $logLevel, string $logChannel): LoggerInterface
+       {
+               return new NullLogger();
+       }
+}
diff --git a/src/Core/Logger/Factory/LoggerFactory.php b/src/Core/Logger/Factory/LoggerFactory.php
new file mode 100644 (file)
index 0000000..0802540
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Core\Logger\Factory;
+
+use Psr\Log\LoggerInterface;
+
+/**
+ * Interface for a logger factory
+ */
+interface LoggerFactory
+{
+       /**
+        * Creates and returns a PSR-3 Logger instance.
+        *
+        * Calling this method multiple times with the same parameters SHOULD return the same object.
+        *
+        * @param \Psr\Log\LogLevel::* $logLevel The log level
+        * @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
+        */
+       public function createLogger(string $logLevel, string $logChannel): LoggerInterface;
+}
diff --git a/tests/Unit/Core/Logger/Factory/LegacyLoggerFactoryTest.php b/tests/Unit/Core/Logger/Factory/LegacyLoggerFactoryTest.php
new file mode 100644 (file)
index 0000000..d888a66
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Test\Unit\Core\Logger\Factory;
+
+use Friendica\Core\Logger\Capability\LogChannel;
+use Friendica\Core\Logger\Factory\LegacyLoggerFactory;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
+
+class LegacyLoggerFactoryTest extends TestCase
+{
+       public function testCreateLoggerReturnsPsrLogger(): void
+       {
+               $factory = new LegacyLoggerFactory();
+
+               $this->assertInstanceOf(
+                       LoggerInterface::class,
+                       $factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
+               );
+       }
+}