tag:support.pimpmylog.com,2013-12-07:/discussions/questions/41-rotated-gzipped-filesPimp my Log: Discussion 2018-07-01T12:35:49Ztag:support.pimpmylog.com,2013-12-07:Comment/361942072015-03-04T13:24:12Z2015-03-04T13:24:13Zrotated gzipped files<div><p>Hello,<br>
we have some files like:</p>
<p>access.log<br>
access.log.1<br>
access.log.1.gz</p>
<p>i cant open the gz ones. Is there any possibility to get them
opened?</p></div>Alextag:support.pimpmylog.com,2013-12-07:Comment/361942072015-03-04T13:41:36Z2015-03-04T13:41:47Zrotated gzipped files<div><p>Hi Alex,</p>
<p>no it is not possible out of the box.</p>
<p>Why don't you change the log rotate configuration ? Just remove
the <code>compress</code> parameter and you are ok !</p></div>potskytag:support.pimpmylog.com,2013-12-07:Comment/361942072015-03-04T14:45:38Z2015-03-04T14:45:39Zrotated gzipped files<div><p>We now have built a quick and dirty fix for our needs ;-)</p>
<p>File "LogParser.php"</p>
<pre>
<code>$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 );</code>
</pre></div>Alextag:support.pimpmylog.com,2013-12-07:Comment/361942072015-03-05T08:59:52Z2015-03-05T08:59:52Zrotated gzipped files<div><p>Dirty indeed :-)</p>
<p>I will try to add this next week an publish a new version if
possible. I will :</p>
<ul>
<li>ensure gzip extension is loaded</li>
<li>try to load data in a streaming way (mandatory to parse big
files)</li>
</ul>
<p>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.</p></div>potskytag:support.pimpmylog.com,2013-12-07:Comment/361942072016-09-26T13:41:22Z2016-09-26T13:41:25Zrotated gzipped files<div><p>Is this already implemented?</p></div>Juan