Skip to content

Commit

Permalink
Fix logLine function and add deprecation notice (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly authored Dec 12, 2023
1 parent b96f98e commit 78132ec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Utilities/FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 8 additions & 2 deletions src/Utilities/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/Utilities/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Utilities/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions tests/Utilities/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 78132ec

Please sign in to comment.