logFile === null) { $this->logFile = \Yii::$app->getRuntimePath() . '/logs/error.json'; } else { $this->logFile = \Yii::getAlias($this->logFile); } $logPath = dirname($this->logFile); if (!is_dir($logPath)) { FileHelper::createDirectory($logPath, $this->dirMode, true); } } public function export() { $exportData = $this->messages; array_push($exportData, date("Y-m-d H:i:s")); $text = json_encode($exportData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ) . ','; if (($fp = @fopen($this->logFile, 'a')) === false) { throw new InvalidConfigException("Unable to append to log file: {$this->logFile}"); } @flock($fp, LOCK_EX); @fwrite($fp, $text); @flock($fp, LOCK_UN); @fclose($fp); if ($this->fileMode !== null) { @chmod($this->logFile, $this->fileMode); } } }