2017 © Pedro Peláez
 

library log-reader

Parse log files

image

innmind/log-reader

Parse log files

  • Thursday, October 12, 2017
  • by Baptouuuu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 232 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 7 % Grown

The README.md

Log reader

Build Status codecov Type Coverage, (*1)

Allow you to parse symfony and apache access logs., (*2)

BEWARE, it can take a lot of time depending on the amount of data (For a typical symfony dev.log it starts to really slow down after 10k lines), (*3)

Installation

composer require innmind/log-reader

Usage

use Innmind\LogReader\{
    Reader\Synchronous,
    Reader\LineParser\Monolog,
    Log,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Url\Path;
use Psr\Log\LogLevel;

$os = Factory::build();

$read = new Synchronous(
    new Monolog($os->clock()),
);
$fs = $os->filesystem()->mount(Path::of('var/logs'));
$read($fs->get('prod.log')->content())
    ->filter(static function(Log $log): bool {
        return $log->attributes()->get('level')->value() === LogLevel::CRITICAL;
    })
    ->foreach(static function(Log $log): void {
        echo $log->attributes()->get('message')->value();
    });

The above example will print all messages that were logged at a critical level., (*4)

Note: if parsing the context or extra attributes of a monolog line fail they won't be exposed as attributes in the Log object. This behaviour is implemented to not make the whole parsing fail due to this error., (*5)

The Versions