rotated gzipped files

Alex's Avatar

Alex

04 Mar, 2015 01:24 PM

Hello,
we have some files like:

access.log
access.log.1
access.log.1.gz

i cant open the gz ones. Is there any possibility to get them opened?

  1. Support Staff 1 Posted by potsky on 04 Mar, 2015 01:41 PM

    potsky's Avatar

    Hi Alex,

    no it is not possible out of the box.

    Why don't you change the log rotate configuration ? Just remove the compress parameter and you are ok !

  2. 2 Posted by Alex on 04 Mar, 2015 02:45 PM

    Alex's Avatar

    We now have built a quick and dirty fix for our needs ;-)

    File "LogParser.php"

    $new_file_path = $file_path;
    if((strlen($file_path) - 3) == strrpos($file_path, ".gz"))
    {

    $zd = gzopen($file_path, "r");
    $contents = gzread($zd, 100*1024*1024);
    gzclose($zd);
    #echo "length string read = " . strlen($contents) . "<br>";
    #echo $contents . "\n\n";
    $new_file_path = "/tmp/" . "pimp_tmp.log";
    file_put_contents($new_file_path, $contents);
    }
    #echo "NEW PATH $new_file_path" . "<br>";
    $fl = fopen( $new_file_path , "r" );
    if ($fl === false) {
    return '1';
    }

            $logs = array();
            $start = microtime( true );
            $regsearch = false;
            $found = false;
            $bytes = 0;
            $skip = 0;
            $error = 0;
            $abort = false;
            $file_lastline = '';
            $search_lastline = true;
            $buffer = array();

            /*
            |--------------------------------------------------------------------------
            | Last modification time and size for this log file
            |--------------------------------------------------------------------------
            |
            */
            if ( version_compare( PHP_VERSION , '5.3.0' ) >= 0 ) {
                $filem = new DateTime( );
                $filem->setTimestamp( filemtime( $new_file_path ) );
            } else {
                $filem = new DateTime( "@" . filemtime( $new_file_path ) );
            }
            if ( ! is_null( $tz ) ) {
                $filem->setTimezone( new DateTimeZone( $tz ) );
            }
            $filemu = $filem->format( 'U' );
            $filem = $filem->format( 'Y/m/d H:i:s' );
            $filesize = filesize( $new_file_path );

  3. Support Staff 3 Posted by potsky on 05 Mar, 2015 08:59 AM

    potsky's Avatar

    Dirty indeed :-)

    I will try to add this next week an publish a new version if possible. I will :

    • ensure gzip extension is loaded
    • try to load data in a streaming way (mandatory to parse big files)

    If it is not possible to load data from the end of the file to the beginning in a stream way, I will not include this feature.

  4. 4 Posted by Juan on 26 Sep, 2016 01:41 PM

    Juan's Avatar

    Is this already implemented?

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac