PHP code example of aarvaos / reporting

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

    

aarvaos / reporting example snippets



const NEUTRAL = 0;
const SERIOUS = 10;
const CRITICAL = 25;

$report = new \Aarvaos\Reporting\Report();

$report->log(1, "Something light happened.");
$report->log(SERIOUS, "Something serious happened!");
$report->log(-4, "Something negligible happened...");

$report->getSeverity(); // 10
$report->hasSeverityReached(9); // true
$report->hasSeverityReached(CRITICAL); // false

$report->getLogs(); // [Log<1, ...>, Log<10, ...>, Log<-4, ...>]

foreach($report->iterateLogs() as $log) {

    // $log = Log<1, ...>,
    // $log = Log<10, ...>,
    // $log = Log<-4, ...>.

}

$report->getLogs(-4); // [Log<-4, ...>]

foreach($report->iterateLogs(\Aarvaos\Reporting\Report::SORT_SEVERITY_ASC, below: 5) as $log) {

    // $log = Log<-4, ...>,
    // $log = Log<1, ...>.

}

$report = new \Aarvaos\Reporting\HookableReport();

$report->registerHook(new \Aarvaos\Reporting\Hooks\ReportSeverityReachHook(10, after: static function(\Aarvaos\Reporting\Events\AfterReportingLogEvent $event): never {
    throw new \RuntimeException($event->log->getPayload());
}));

$report(10, 'Error!'); // Exception