PHP code example of sbwerewolf / subprocess-logger

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

    

sbwerewolf / subprocess-logger example snippets


use Integration\FileLogger;
use SbWereWolf\BatchLogger\ArchivistFactory;
     
$filePath = date('Ymd') . '.log';
$file = fopen($filePath, 'a');        
$logger = new FileLogger($file);

$toLevel = [
        'debug' => 7,
        'info' => 6,
        'notice' => 5,
        'warning' => 4,
        'error' => 3,
        'critical' => 2,
        'alert' => 1,
        'emergency' => 0,
    ];

$archivist = (new ArchivistFactory())
    ->setParent('Global process')
    ->setChild('Example of Archivist using')
    ->setConverting($toLevel)
    ->setLevel('debug')
    ->make($logger);        
try {
    $archivist->start('notice', 'start process');
    /* Add to journal some algorithm notes */
    $archivist->debug('some debug info');
    /* If process finish with no errors - write brief to logs */
    $archivist->writeBrief(
        'notice', 
        'process finish with success'
    );
} catch (Throwable $e) {
    $message = "message: {$e->getMessage()}," .
        " trace:{$e->getTraceAsString()}";
    $archivist->critical($message);

    /* If some exception will occur - write detail logs */
    $archivist->writeDetails(
        'notice',
        'process finish with failure'
    );
}
fclose($file);