PHP code example of lander931 / log-reader

1. Go to this page and download the library: Download lander931/log-reader 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/ */

    

lander931 / log-reader example snippets


$reader = LogReader::read($log_content, function($text) {
    return explode("\n", $text);
})

$reader->buildEntries(function ($log){
    $pattern = "/\[(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})\] (.+)/";
    preg_match_all($pattern, $log, $matches, PREG_SET_ORDER);

    $date = $matches[0][1];
    $time = $matches[0][2];
    $message = $matches[0][3];

    return new LogEntity($date, $time, $message);
});

$res = $reader->getEntries();
text
array(2) {
    [0] => object(LogEntity) {
        ["date"]    => "2018-01-01"
        ["time"]    => "15:00:00"
        ["message"] => "log 1"
    }
    [1] => object(LogEntity) {
        ["date"]    => "2018-01-01"
        ["time"]    => "15:00:05"
        ["message"] => "log 2"
    }
}