PHP code example of webfiori / log

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

    

webfiori / log example snippets


use WebFiori\Log\FileLogger;
use WebFiori\Log\LogLevel;

$logger = new FileLogger('/var/log/myapp', LogLevel::INFO);

$logger->info('User logged in', ['user_id' => 42, 'ip' => '192.168.1.1']);
$logger->error('Payment failed', ['order_id' => 123, 'reason' => 'timeout']);
$logger->debug('This will be filtered out'); // below INFO threshold

use WebFiori\Log\LoggerFacade;

LoggerFacade::info('Application started');
LoggerFacade::error('Something went wrong', ['exception' => $e->getMessage()]);

use WebFiori\Log\Logger;

class DatabaseLogger implements Logger {
    public function debug(string $message, array $context = []): void { /* ... */ }
    public function info(string $message, array $context = []): void { /* ... */ }
    public function warning(string $message, array $context = []): void { /* ... */ }
    public function error(string $message, array $context = []): void { /* ... */ }
    public function critical(string $message, array $context = []): void { /* ... */ }
    public function log(string $level, string $message, array $context = []): void { /* ... */ }
}

LoggerFacade::setInstance(new DatabaseLogger());

[2026-05-29 01:00:00] [INFO] User logged in {"user_id":42,"ip":"192.168.1.1"}
[2026-05-29 01:00:00] [ERROR] Payment failed {"order_id":123,"reason":"timeout"}