PHP code example of julesgraus / quatsch

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

    

julesgraus / quatsch example snippets


use \JulesGraus\Quatsch\Pattern\Pattern;
use \JulesGraus\Quatsch\Pattern\Enums\RegexModifier;
use \JulesGraus\Quatsch\Pattern\StringPatternInspector;
use \JulesGraus\Quatsch\Tasks\ExtractTask;
use \JulesGraus\Quatsch\Tasks\Enums\FileMode;
use \JulesGraus\Quatsch\Resources\FileResource;
use \JulesGraus\Quatsch\ResourceAlgorithms\SlidingWindowChunkProcessor

$errorPattern = Pattern::contains(Pattern::quote('['))
    ->digit()->times(4)
    ->then('-')
    ->digit()->times(2)
    ->then('-')
    ->digit()->times(2)
    ->then(' ')
    ->digit()->times(2)
    ->then(':')
    ->digit()->times(2)
    ->then(':')
    ->digit()->times(2)
    ->then(Pattern::quote(']'))
    ->singleCharacter()->oneOrMoreTimes()
    ->multiLineEndOfString()
    ->addModifier(RegexModifier::MULTILINE)
    ->addModifier(RegexModifier::GLOBAL);

$inputResource = new FileResource(
    path: __DIR__ . '/../fixtures/laravel.log',
    mode: FileMode::READ,
);

$outputResource = new FileResource(
    path: __DIR__ . '/../fixtures/laravel_parsed.log',
    mode: FileMode::READ_APPEND,
);

$task = new ExtractTask(
    patternToExtract: $errorPattern,
    slidingWindowChunkProcessor: new SlidingWindowChunkProcessor(
        chunkSize: 20,
        maximumExpectedMatchLength: 1000,
        stringPatternInspector: new StringPatternInspector(),
    ),
);

$task(inputResource: $inputResource, outputResourceOrOutputRedirector: $outputResource);