framework/log/FileTarget.php
public function export()
    {
        $logPath = dirname($this->logFile);
        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}");
        }
        @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) {
            @flock($fp, LOCK_UN);
            @fclose($fp);
            $this->rotateFiles();
            $writeResult = @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX);
            if ($writeResult === false) {
                $error = error_get_last();
                throw new LogRuntimeException("Unable to export log through file!: {$error['message']}");
            }
            $textSize = strlen($text);
            if ($writeResult < $textSize) {
                throw new LogRuntimeException("Unable to export whole log through file! Wrote $writeResult out of $textSize bytes.");
            }
        } else {
            $writeResult = @fwrite($fp, $text);
            if ($writeResult === false) {
                $error = error_get_last();
                throw new LogRuntimeException("Unable to export log through file!: {$error['message']}");
            }
            $textSize = strlen($text);
            if ($writeResult < $textSize) {
                throw new LogRuntimeException("Unable to export whole log through file! Wrote $writeResult out of $textSize bytes.");
            }
            @flock($fp, LOCK_UN);
            @fclose($fp);
        }
        if ($this->fileMode !== null) {
            @chmod($this->logFile, $this->fileMode);
        }
    }
public function export()
    {
        $logPath = dirname($this->logFile);
        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}");
        }
        @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) {
            @flock($fp, LOCK_UN);
            @fclose($fp);
            $this->rotateFiles();
            $writeResult = @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX);
            if ($writeResult === false) {
                $error = error_get_last();
                throw new LogRuntimeException("Unable to export log through file!: {$error['message']}");
            }
            $textSize = strlen($text);
            if ($writeResult < $textSize) {
                throw new LogRuntimeException("Unable to export whole log through file! Wrote $writeResult out of $textSize bytes.");
            }
        } else {
            $writeResult = @fwrite($fp, $text);
            if ($writeResult === false) {
                $error = error_get_last();
                throw new LogRuntimeException("Unable to export log through file!: {$error['message']}");
            }
            $textSize = strlen($text);
            if ($writeResult < $textSize) {
                throw new LogRuntimeException("Unable to export whole log through file! Wrote $writeResult out of $textSize bytes.");
            }
            @flock($fp, LOCK_UN);
            @fclose($fp);
        }
        if ($this->fileMode !== null) {
            @chmod($this->logFile, $this->fileMode);
        }
    }
public function export ( ) { $ logPath = dirname ( $ this -> logFile ) ; 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}" ) ; } @ 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 ) { @ flock ( $ fp , LOCK_UN ) ; @ fclose ( $ fp ) ; $ this -> rotateFiles ( ) ; $ writeResult = @ file_put_contents ( $ this -> logFile , $ text , FILE_APPEND | LOCK_EX ) ; if ( $ writeResult === false ) { $ error = error_get_last ( ) ; throw new LogRuntimeException ( "Unable to export log through file!: {$error['message']}" ) ; } $ textSize = strlen ( $ text ) ; if ( $ writeResult < $ textSize ) { throw new LogRuntimeException ( "Unable to export whole log through file! Wrote $writeResult out of $textSize bytes." ) ; } } else { $ writeResult = @ fwrite ( $ fp , $ text ) ; if ( $ writeResult === false ) { $ error = error_get_last ( ) ; throw new LogRuntimeException ( "Unable to export log through file!: {$error['message']}" ) ; } $ textSize = strlen ( $ text ) ; if ( $ writeResult < $ textSize ) { throw new LogRuntimeException ( "Unable to export whole log through file! Wrote $writeResult out of $textSize bytes." ) ; } @ flock ( $ fp , LOCK_UN ) ; @ fclose ( $ fp ) ; } if ( $ this -> fileMode !== null ) { @ chmod ( $ this -> logFile , $ this -> fileMode ) ; } }
Writes log messages to a file.
Starting from version 2.0.14, this method throws LogRuntimeException in case the log can not be exported.
@throws InvalidConfigException if unable to open the log file for writing
@throws LogRuntimeException if unable to write complete log to file
Writes log messages to a file . Starting from version 2 . 0 . 14 this method throws LogRuntimeException in case the log can not be exported .