mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
File Log writer without newline. (#19941)
* File Log writer without newline. * Fix minor correction. * Fix tests. * Add more test. * Add line to CHANGELOG.md.
This commit is contained in:
@ -4,7 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.50 under development
|
2.0.50 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
- no changes in this release.
|
- Bug #19940: File Log writer without newline (terabytesoftw)
|
||||||
|
|
||||||
|
|
||||||
2.0.49 August 29, 2023
|
2.0.49 August 29, 2023
|
||||||
|
|||||||
@ -130,12 +130,12 @@ class FileTarget extends Target
|
|||||||
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
|
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
|
||||||
$this->rotateFiles();
|
$this->rotateFiles();
|
||||||
}
|
}
|
||||||
$writeResult = @fwrite($fp, $trimmedText);
|
$writeResult = @fwrite($fp, $text);
|
||||||
if ($writeResult === false) {
|
if ($writeResult === false) {
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}");
|
throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}");
|
||||||
}
|
}
|
||||||
$textSize = strlen($trimmedText);
|
$textSize = strlen($text);
|
||||||
if ($writeResult < $textSize) {
|
if ($writeResult < $textSize) {
|
||||||
throw new LogRuntimeException("Unable to export whole log through file ({$this->logFile})! Wrote $writeResult out of $textSize bytes.");
|
throw new LogRuntimeException("Unable to export whole log through file ({$this->logFile})! Wrote $writeResult out of $textSize bytes.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -123,7 +123,19 @@ class FileTargetTest extends TestCase
|
|||||||
$logger->export();
|
$logger->export();
|
||||||
|
|
||||||
$test = file($logFile);
|
$test = file($logFile);
|
||||||
$this->assertEquals("xxx", $test[0]);
|
$this->assertEquals("xxx\n", $test[0]);
|
||||||
|
|
||||||
|
$this->clearLogFile($logFile);
|
||||||
|
|
||||||
|
$logger = new CustomLogger();
|
||||||
|
$logger->logFile = $logFile;
|
||||||
|
$logger->messages = array_fill(0, 3, 'xxx');
|
||||||
|
$logger->export();
|
||||||
|
|
||||||
|
$test = file($logFile);
|
||||||
|
$this->assertEquals("xxx\n", $test[0]);
|
||||||
|
$this->assertEquals("xxx\n", $test[1]);
|
||||||
|
$this->assertEquals("xxx\n", $test[2]);
|
||||||
|
|
||||||
$this->clearLogFile($logFile);
|
$this->clearLogFile($logFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user