Directory creation is moved to export() method

This commit is contained in:
Dmitry Alekseev
2018-02-18 12:57:09 +03:00
parent d131d08ce1
commit 1b14628dbf
2 changed files with 22 additions and 4 deletions

View File

@ -85,10 +85,6 @@ class FileTarget extends Target
} else {
$this->logFile = Yii::getAlias($this->logFile);
}
$logPath = dirname($this->logFile);
if (!is_dir($logPath)) {
FileHelper::createDirectory($logPath, $this->dirMode, true);
}
if ($this->maxLogFiles < 1) {
$this->maxLogFiles = 1;
}
@ -105,6 +101,11 @@ class FileTarget extends Target
*/
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";
if (($fp = @fopen($this->logFile, 'a')) === false) {
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");