PHP code example of mvar / log-parser

1. Go to this page and download the library: Download mvar/log-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mvar / log-parser example snippets




Var\LogParser\LogIterator;
use MVar\LogParser\SimpleParser;  

// Pass your regular expression
$parser = new SimpleParser('/(?<method>\S+)\s+(?<path>\S+)\s+(?<response_code>\d+)/');

foreach (new LogIterator('my.log', $parser) as $data) {
    var_export($data);
    echo "\n";
}

array (
  'method' => 'GET',
  'path' => '/favicon.ico',
  'response_code' => '200',
)
array (
  'method' => 'GET',
  'path' => '/about',
  'response_code' => '404',
)

$logFile = 'compress.zlib://file:///path/to/log.gz';