PHP code example of orbiit / logger

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

    

orbiit / logger example snippets


use Orbiit\Logger\Logger;
use Orbiit\Logger\Handlers\FileHandler;
use Orbiit\Logger\Enums\Level;

// 1. Setup handler
$handler = new FileHandler(DIR . '/logs/app.log', Level::DEBUG);

// 2. Initialize Logger
$logger = new Logger([$handler]);

// 3. Log securely
$logger->info('New sale processed', [
    'order_id' => '1025',
    'customer_cpf' => '123.456.789-00', // Auto-masked
    'total' => 250.50
]);

$router->add('POST', '/api/v1/login', function() use ($logger) {
    $logger->notice('Login attempt', $_POST);
});

try {
    $payment->process($creditCard);
} catch (PaymentException $e) {
    $logger->error('Payment failed', [
        'reason' => $e->getMessage(),
        'card_number' => $creditCard->number,
        'terminal_id' => 'PDV-65'
    ]);
}

$logger->info('Venda realizada', [
    'cpf' => '123.456.789-00', // mascarado automaticamente
]);

$logger->notice('Tentativa de login', $_POST);

$logger->error('Falha no pagamento', [
    'cartao' => '****'
]);