2017 © Pedro Peláez
 

library log-parser

Universal log parser

image

mvar/log-parser

Universal log parser

  • Tuesday, January 23, 2018
  • by mvar
  • Repository
  • 1 Watchers
  • 7 Stars
  • 1,522 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 3 Versions
  • 19 % Grown

The README.md

Server Log Parser

Latest Stable Version Build Status Code Coverage Code Quality, (*1)

This library allows you to easily iterate over your Apache, nginx or any other web server log files., (*2)

Main features:, (*3)

  • Log file iterator
  • Parser abstraction to help you implement your custom parser
  • Low memory footprint even with huge files

Installation

This library can be found on Packagist. The recommended way to install this is through Composer:, (*4)

composer require mvar/log-parser:^1.0

Basic Usage

Lets say you have log file my.log with following content:, (*5)

GET /favicon.ico 200
GET /about 404

All you need to do to iterate over the file is to initialize SimpleParser with your regular expression and pass it to LogIterator:, (*6)

<?php

require __DIR__ . '/vendor/autoload.php';

use MVar\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";
}

The above example will output:, (*7)

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

It is also possible to parse compressed files by adding stream wrapper before file name:, (*8)

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

How To

Implemented Parsers

  • [mvar/apache2-log-parser][3] - Apache access/error log parser based on this library

License

This package is licensed under the MIT License. See the LICENSE file for details., (*9)

The Versions

23/01 2018

dev-master

9999999-dev

Universal log parser

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Mantas Varatiejus

13/06 2017

v1.1.0

1.1.0.0

Universal log parser

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Mantas Varatiejus

20/12 2015

v1.0.0

1.0.0.0

Universal log parser

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Mantas Varatiejus