protected function rotate($fileToRotate)
    {

        // clear the filesystem cache
        clearstatcache();

        // query whether the file is NOT available anymore or we dont have access to it
        if (file_exists($fileToRotate) === false ||
            is_writable($fileToRotate) === false) {
            return;
        }

        // query whether the file has any content, because we don't want to rotate empty files
        if (filesize($fileToRotate) === 0) {
            return;
        }

        // load the existing log files
        $logFiles = glob($this->getGlobPattern($fileToRotate, 'gz'));

        // sorting the files by name to remove the older ones
        usort(
            $logFiles,
            function ($a, $b) {
                return strcmp($b, $a);
            }
        );

        // load the information about the found file
        $dirname = pathinfo($fileToRotate, PATHINFO_DIRNAME);
        $filename = pathinfo($fileToRotate, PATHINFO_FILENAME);

        // raise the counter of the rotated files
        foreach ($logFiles as $fileToRename) {
            // load the information about the found file
            $extension = pathinfo($fileToRename, PATHINFO_EXTENSION);
            $basename = pathinfo($fileToRename, PATHINFO_BASENAME);

            // prepare the regex to grep the counter with
            $regex = sprintf('/^%s\.([0-9]{1,})\.%s/', $filename, $extension);

            // initialize the counter for the regex result
            $counter = array();

            // check the counter
            if (preg_match($regex, $basename, $counter)) {
                // load and raise the counter by one
                $raised = ((integer) end($counter)) + 1;

                // prepare the new filename
                $newFilename = sprintf('%s/%s.%d.%s', $dirname, $filename, $raised, $extension);

                // rename the file
                rename($fileToRename, $newFilename);
            }
        }

        // rotate the file
        rename($fileToRotate, $newFilename = sprintf('%s/%s.0', $dirname, $filename));

        // compress the log file
        file_put_contents("compress.zlib://$newFilename.gz", file_get_contents($newFilename));

        // delete the old file
        unlink($newFilename);

        // next rotation date is tomorrow
        $tomorrow = new \DateTime('tomorrow');
        $this->setNextRotationDate($tomorrow->getTimestamp());
    }
protected function rotate($fileToRotate)
    {

        // clear the filesystem cache
        clearstatcache();

        // query whether the file is NOT available anymore or we dont have access to it
        if (file_exists($fileToRotate) === false ||
            is_writable($fileToRotate) === false) {
            return;
        }

        // query whether the file has any content, because we don't want to rotate empty files
        if (filesize($fileToRotate) === 0) {
            return;
        }

        // load the existing log files
        $logFiles = glob($this->getGlobPattern($fileToRotate, 'gz'));

        // sorting the files by name to remove the older ones
        usort(
            $logFiles,
            function ($a, $b) {
                return strcmp($b, $a);
            }
        );

        // load the information about the found file
        $dirname = pathinfo($fileToRotate, PATHINFO_DIRNAME);
        $filename = pathinfo($fileToRotate, PATHINFO_FILENAME);

        // raise the counter of the rotated files
        foreach ($logFiles as $fileToRename) {
            // load the information about the found file
            $extension = pathinfo($fileToRename, PATHINFO_EXTENSION);
            $basename = pathinfo($fileToRename, PATHINFO_BASENAME);

            // prepare the regex to grep the counter with
            $regex = sprintf('/^%s\.([0-9]{1,})\.%s/', $filename, $extension);

            // initialize the counter for the regex result
            $counter = array();

            // check the counter
            if (preg_match($regex, $basename, $counter)) {
                // load and raise the counter by one
                $raised = ((integer) end($counter)) + 1;

                // prepare the new filename
                $newFilename = sprintf('%s/%s.%d.%s', $dirname, $filename, $raised, $extension);

                // rename the file
                rename($fileToRename, $newFilename);
            }
        }

        // rotate the file
        rename($fileToRotate, $newFilename = sprintf('%s/%s.0', $dirname, $filename));

        // compress the log file
        file_put_contents("compress.zlib://$newFilename.gz", file_get_contents($newFilename));

        // delete the old file
        unlink($newFilename);

        // next rotation date is tomorrow
        $tomorrow = new \DateTime('tomorrow');
        $this->setNextRotationDate($tomorrow->getTimestamp());
    }
protected function rotate ( $ fileToRotate ) { // clear the filesystem cache clearstatcache ( ) ; // query whether the file is NOT available anymore or we dont have access to it if ( file_exists ( $ fileToRotate ) === false || is_writable ( $ fileToRotate ) === false ) { return ; } // query whether the file has any content, because we don't want to rotate empty files if ( filesize ( $ fileToRotate ) === 0 ) { return ; } // load the existing log files $ logFiles = glob ( $ this -> getGlobPattern ( $ fileToRotate , 'gz' ) ) ; // sorting the files by name to remove the older ones usort ( $ logFiles , function ( $ a , $ b ) { return strcmp ( $ b , $ a ) ; } ) ; // load the information about the found file $ dirname = pathinfo ( $ fileToRotate , PATHINFO_DIRNAME ) ; $ filename = pathinfo ( $ fileToRotate , PATHINFO_FILENAME ) ; // raise the counter of the rotated files foreach ( $ logFiles as $ fileToRename ) { // load the information about the found file $ extension = pathinfo ( $ fileToRename , PATHINFO_EXTENSION ) ; $ basename = pathinfo ( $ fileToRename , PATHINFO_BASENAME ) ; // prepare the regex to grep the counter with $ regex = sprintf ( '/^%s\.([0-9]{1,})\.%s/' , $ filename , $ extension ) ; // initialize the counter for the regex result $ counter = array ( ) ; // check the counter if ( preg_match ( $ regex , $ basename , $ counter ) ) { // load and raise the counter by one $ raised = ( ( integer ) end ( $ counter ) ) + 1 ; // prepare the new filename $ newFilename = sprintf ( '%s/%s.%d.%s' , $ dirname , $ filename , $ raised , $ extension ) ; // rename the file rename ( $ fileToRename , $ newFilename ) ; } } // rotate the file rename ( $ fileToRotate , $ newFilename = sprintf ( '%s/%s.0' , $ dirname , $ filename ) ) ; // compress the log file file_put_contents ( "compress.zlib://$newFilename.gz" , file_get_contents ( $ newFilename ) ) ; // delete the old file unlink ( $ newFilename ) ; // next rotation date is tomorrow $ tomorrow = new \ DateTime ( 'tomorrow' ) ; $ this -> setNextRotationDate ( $ tomorrow -> getTimestamp ( ) ) ; }
Does the rotation of the log file which includes updating the currently
used filename as well as cleaning up the log directory.

@param string $fileToRotate The file to be rotated

@return void
Does the rotation of the log file which includes updating the currently used filename as well as cleaning up the log directory .