mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Directory creation is moved to export() method
This commit is contained in:
@ -85,10 +85,6 @@ class FileTarget extends Target
|
|||||||
} else {
|
} else {
|
||||||
$this->logFile = Yii::getAlias($this->logFile);
|
$this->logFile = Yii::getAlias($this->logFile);
|
||||||
}
|
}
|
||||||
$logPath = dirname($this->logFile);
|
|
||||||
if (!is_dir($logPath)) {
|
|
||||||
FileHelper::createDirectory($logPath, $this->dirMode, true);
|
|
||||||
}
|
|
||||||
if ($this->maxLogFiles < 1) {
|
if ($this->maxLogFiles < 1) {
|
||||||
$this->maxLogFiles = 1;
|
$this->maxLogFiles = 1;
|
||||||
}
|
}
|
||||||
@ -105,6 +101,11 @@ class FileTarget extends Target
|
|||||||
*/
|
*/
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
|
$logPath = dirname($this->logFile);
|
||||||
|
if (!is_dir($logPath)) {
|
||||||
|
FileHelper::createDirectory($logPath, $this->dirMode, true);
|
||||||
|
}
|
||||||
|
|
||||||
$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
|
$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
|
||||||
if (($fp = @fopen($this->logFile, 'a')) === false) {
|
if (($fp = @fopen($this->logFile, 'a')) === false) {
|
||||||
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
|
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
|
||||||
|
|||||||
@ -10,6 +10,7 @@ namespace yiiunit\framework\log;
|
|||||||
use Yii;
|
use Yii;
|
||||||
use yii\helpers\FileHelper;
|
use yii\helpers\FileHelper;
|
||||||
use yii\log\Dispatcher;
|
use yii\log\Dispatcher;
|
||||||
|
use yii\log\FileTarget;
|
||||||
use yii\log\Logger;
|
use yii\log\Logger;
|
||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
|
|
||||||
@ -32,6 +33,22 @@ class FileTargetTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function testInit()
|
||||||
|
{
|
||||||
|
$logFile = Yii::getAlias('@yiiunit/runtime/log/filetargettest.log');
|
||||||
|
FileHelper::removeDirectory(dirname($logFile));
|
||||||
|
new FileTarget([
|
||||||
|
'logFile' => Yii::getAlias('@yiiunit/runtime/log/filetargettest.log'),
|
||||||
|
]);
|
||||||
|
$this->assertFileNotExists(
|
||||||
|
dirname($logFile),
|
||||||
|
'Log directory should not be created during init process'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider booleanDataProvider
|
* @dataProvider booleanDataProvider
|
||||||
* @param bool $rotateByCopy
|
* @param bool $rotateByCopy
|
||||||
|
|||||||
Reference in New Issue
Block a user