PHP code example of eliashaeussler / transient-logger

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

    

eliashaeussler / transient-logger example snippets


use EliasHaeussler\TransientLogger;

$logger = new TransientLogger\TransientLogger();

// Log using generic log() method
$logger->log(
    TransientLogger\Log\LogLevel::Alert,
    'Houston, we have a problem!',
    ['error' => 'rocket down'],
);

// Log using specific methods
$logger->alert('Houston, we have a problem!', ['error' => 'rocket down']);

// Get all log records
$logs = $logger->getAll();

// Get by specific log level
$errors = $logger->getByLogLevel(TransientLogger\Log\LogLevel::Error);

// Iterate over log records
foreach ($logger as $logRecord) {
    $level = $logRecord->level; // instanceof \EliasHaeussler\TransientLogger\Log\LogLevel
    $message = $logRecord->message; // string or instanceof Stringable
    $context = $logRecord->context; // array<string, mixed>
}

$logger->flushLog();