Skip to content

Commit

Permalink
Apply suggestion review bizley.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jul 18, 2023
1 parent fa9a390 commit 2b586f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions framework/log/FileTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,18 @@ public function init()
*/
public function export()
{
if (strpos($this->logFile, '://') === false || strncmp($this->logFile, 'file://', 7) === 0) {
$logPath = dirname($this->logFile);
FileHelper::createDirectory($logPath, $this->dirMode, true);
}

$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";

$trimmedText = trim($text);

if (empty($trimmedText)) {
return; // No messages to export, so we exit the function early
}

Check warning on line 114 in framework/log/FileTarget.php

View check run for this annotation

Codecov / codecov/patch

framework/log/FileTarget.php#L114

Added line #L114 was not covered by tests

if (strpos($this->logFile, '://') === false || strncmp($this->logFile, 'file://', 7) === 0) {
$logPath = dirname($this->logFile);
FileHelper::createDirectory($logPath, $this->dirMode, true);
}

if (($fp = @fopen($this->logFile, 'a')) === false) {
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
}
Expand All @@ -131,12 +130,12 @@ public function export()
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
$this->rotateFiles();
}
$writeResult = @fwrite($fp, $text);
$writeResult = @fwrite($fp, $trimmedText);
if ($writeResult === false) {
$error = error_get_last();
throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}");
}
$textSize = strlen($text);
$textSize = strlen($trimmedText);
if ($writeResult < $textSize) {
throw new LogRuntimeException("Unable to export whole log through file ({$this->logFile})! Wrote $writeResult out of $textSize bytes.");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/log/FileTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testLogEmptyStrings()
$logger->export();

$test = file($logFile);
$this->assertEquals("xxx\n", $test[0]);
$this->assertEquals("xxx", $test[0]);

$this->clearLogFile($logFile);

Expand Down

0 comments on commit 2b586f8

Please sign in to comment.