public function log(string $message, string $path = null, array $options = []): void
    {
        $options =
            $options +
            (is_null($path) ? [] : ['path' => $path]) +
            $this->defaults;
        $path = $options['path'];
        if (is_null($path)) {
            throw new \RuntimeException("Missing path");
        }
        $realPath = realpath(dirname($path));
        if (FALSE === $realPath) {
            throw new \RuntimeException(sprintf(
                "Invalid directory '%s'",
                $path
            ));
        }
        $path = sprintf(
            "%s/%s",
            $realPath,
            basename($path)
        );
        clearstatcache(true, $path);
        if (file_exists($path) && (filesize($path) > $options['maxSize'])) {
            for ($i = $options['rotation']; $i > 0; --$i) {
                $destPath = sprintf("%s.%d", $path, $i);
                if (file_exists($destPath)) {
                    unlink($destPath);
                }
                $sourcePath = $i > 1 ? sprintf("%s.%d", $path, $i - 1) : $path;
                if (file_exists($sourcePath)) {
                    rename($sourcePath, $destPath);
                }
            }
            if (file_exists($path)) {
                unlink($path);
            }
        }
        file_put_contents($path, $message, FILE_APPEND);
        if (!is_null($options['rights'])) {
            chmod($path, $options['rights']);
        }
    }
public function log(string $message, string $path = null, array $options = []): void
    {
        $options =
            $options +
            (is_null($path) ? [] : ['path' => $path]) +
            $this->defaults;
        $path = $options['path'];
        if (is_null($path)) {
            throw new \RuntimeException("Missing path");
        }
        $realPath = realpath(dirname($path));
        if (FALSE === $realPath) {
            throw new \RuntimeException(sprintf(
                "Invalid directory '%s'",
                $path
            ));
        }
        $path = sprintf(
            "%s/%s",
            $realPath,
            basename($path)
        );
        clearstatcache(true, $path);
        if (file_exists($path) && (filesize($path) > $options['maxSize'])) {
            for ($i = $options['rotation']; $i > 0; --$i) {
                $destPath = sprintf("%s.%d", $path, $i);
                if (file_exists($destPath)) {
                    unlink($destPath);
                }
                $sourcePath = $i > 1 ? sprintf("%s.%d", $path, $i - 1) : $path;
                if (file_exists($sourcePath)) {
                    rename($sourcePath, $destPath);
                }
            }
            if (file_exists($path)) {
                unlink($path);
            }
        }
        file_put_contents($path, $message, FILE_APPEND);
        if (!is_null($options['rights'])) {
            chmod($path, $options['rights']);
        }
    }
public function log ( string $ message , string $ path = null , array $ options = [ ] ) : void { $ options = $ options + ( is_null ( $ path ) ? [ ] : [ 'path' => $ path ] ) + $ this -> defaults ; $ path = $ options [ 'path' ] ; if ( is_null ( $ path ) ) { throw new \ RuntimeException ( "Missing path" ) ; } $ realPath = realpath ( dirname ( $ path ) ) ; if ( FALSE === $ realPath ) { throw new \ RuntimeException ( sprintf ( "Invalid directory '%s'" , $ path ) ) ; } $ path = sprintf ( "%s/%s" , $ realPath , basename ( $ path ) ) ; clearstatcache ( true , $ path ) ; if ( file_exists ( $ path ) && ( filesize ( $ path ) > $ options [ 'maxSize' ] ) ) { for ( $ i = $ options [ 'rotation' ] ; $ i > 0 ; -- $ i ) { $ destPath = sprintf ( "%s.%d" , $ path , $ i ) ; if ( file_exists ( $ destPath ) ) { unlink ( $ destPath ) ; } $ sourcePath = $ i > 1 ? sprintf ( "%s.%d" , $ path , $ i - 1 ) : $ path ; if ( file_exists ( $ sourcePath ) ) { rename ( $ sourcePath , $ destPath ) ; } } if ( file_exists ( $ path ) ) { unlink ( $ path ) ; } } file_put_contents ( $ path , $ message , FILE_APPEND ) ; if ( ! is_null ( $ options [ 'rights' ] ) ) { chmod ( $ path , $ options [ 'rights' ] ) ; } }
Rotate log files and logs message.

@param string $message
@param string $path     If null passed will be used from options
@param array  $options

@return void

@throws \RuntimeException  If path taken from args and options are missing.
@throws \RuntimeException  If directory from path is invalid.

@see self::__construct()  $options parameter description
Rotate log files and logs message .