yii\log\FileTarget::export PHP Method

export() public method

Writes log messages to a file.
public export ( )
    public function export()
    {
        $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}");
        }
        @flock($fp, LOCK_EX);
        if ($this->enableRotation) {
            // clear stat cache to ensure getting the real current file size and not a cached one
            // this may result in rotating twice when cached file size is used on subsequent calls
            clearstatcache();
        }
        if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
            $this->rotateFiles();
            @flock($fp, LOCK_UN);
            @fclose($fp);
            @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX);
        } else {
            @fwrite($fp, $text);
            @flock($fp, LOCK_UN);
            @fclose($fp);
        }
        if ($this->fileMode !== null) {
            @chmod($this->logFile, $this->fileMode);
        }
    }

Usage Example

Beispiel #1
0
 public function recode_log($msg)
 {
     $log = new FileTarget();
     $log->logFile = Yii::$app->getRuntimePath() . '/logs/wx_debug_' . date("Y-m-d") . '.log';
     $log->messages[] = [$msg, 1, 'application', microtime(true)];
     $log->export();
 }
All Usage Examples Of yii\log\FileTarget::export