From 78132ec3a0e920044a6f171aadd02e04b4852764 Mon Sep 17 00:00:00 2001 From: s4ddly <110701663+s4ddly@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:42:24 +0100 Subject: [PATCH] Fix logLine function and add deprecation notice (#67) --- src/Utilities/FileLogger.php | 13 +++++++++++++ src/Utilities/Logger.php | 10 ++++++++-- src/Utilities/Util.php | 4 ++++ tests/Utilities/LoggerTest.php | 10 ++++++++++ tests/Utilities/UtilTest.php | 12 ++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Utilities/FileLogger.php b/src/Utilities/FileLogger.php index 3f3768e..7fb5e4d 100644 --- a/src/Utilities/FileLogger.php +++ b/src/Utilities/FileLogger.php @@ -18,6 +18,19 @@ public function log($level, $message, array $context = []) $this->info($message); } + /** + * @param string $text + * + * @throws TException + * + * @deprecated 3.0.0 + */ + public function logLine($text) + { + $this->checkLogFile(); + file_put_contents($this->getLogPath(), $text.PHP_EOL, FILE_APPEND); + } + /** * @param string $message * diff --git a/src/Utilities/Logger.php b/src/Utilities/Logger.php index b41c719..a079ccf 100644 --- a/src/Utilities/Logger.php +++ b/src/Utilities/Logger.php @@ -77,9 +77,15 @@ public static function log($title, $text, $logLevel = 'info') self::getLogger()->log($logLevel, json_encode($content)); } - /** @param string $text */ + /** + * @param string $text + * + * @throws TException + * + * @deprecated 3.0.0 + */ public static function logLine($text) { - self::$logger->info((string) $text); + self::getLogger()->logLine($text); } } diff --git a/src/Utilities/Util.php b/src/Utilities/Util.php index cdece2d..cb914f2 100644 --- a/src/Utilities/Util.php +++ b/src/Utilities/Util.php @@ -92,6 +92,10 @@ public static function log($title, $text) * Save one line to log file * * @param string $text text to save + * + * @throws TException + * + * @deprecated 3.0.0 */ public static function logLine($text) { diff --git a/tests/Utilities/LoggerTest.php b/tests/Utilities/LoggerTest.php index bf5dd10..cb05468 100644 --- a/tests/Utilities/LoggerTest.php +++ b/tests/Utilities/LoggerTest.php @@ -19,6 +19,16 @@ public function testLogged() $this->deleteTestLog(); } + public function testLineLogged() + { + Logger::logLine('test'); + + $this->assertFileExists($this->logFilename()); + + // tearDown + $this->deleteTestLog(); + } + public function testDisableLogging() { Logger::disableLogging(); diff --git a/tests/Utilities/UtilTest.php b/tests/Utilities/UtilTest.php index 86452f1..b630dc3 100644 --- a/tests/Utilities/UtilTest.php +++ b/tests/Utilities/UtilTest.php @@ -19,6 +19,18 @@ public function testLogged() $this->deleteTestLog(); } + public function testLineLogged() + { + Util::$loggingEnabled = true; + Util::$customLogPatch = null; + + Util::logLine('test'); + + $this->assertFileExists($this->logFilename()); + + $this->deleteTestLog(); + } + public function testDisableLogging() { Util::$loggingEnabled = false;