PHP code example of azurre / php-simple-logger

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

    

azurre / php-simple-logger example snippets


use \Azurre\Component\Logger;
use \Azurre\Component\Logger\Handler\File;

$logger = new Logger();
$logger->info('Simple Logger really is simple.');

use \Azurre\Component\Logger;
use \Azurre\Component\Logger\Handler\File;

$logfile = '/var/log/events.log';
$channel = 'billing';
$logger  = new Logger($channel);
$logger->setHandler(new File($logfile));

$logger->info('Begin process that usually fails.', ['process' => 'invoicing', 'user' => $user]);

try {
    invoiceUser($user); // This usually fails
} catch (\Exception $e) {
    $logger->error('Billing failure.', ['process' => 'invoicing', 'user' => $user, 'exception' => $e]);
}

$logger->debug('Detailed information about the application run.');
$logger->info('Informational messages about the application run.');
$logger->notice('Normal but significant events.');
$logger->warning('Information that something potentially bad has occured.');
$logger->error('Runtime error that should be monitored.');
$logger->critical('A service is unavailable or unresponsive.');
$logger->alert('The entire site is down.');
$logger->emergency('The Web site is on fire.');

use \Psr\Log\LogLevel;
use \Azurre\Component\Logger;

// Optional constructor Parameter (Only error and above are logged [error, critical, alert, emergency])
$logger = new Logger($channel, LogLevel::ERROR);

// Setter method (Only warning and above are logged)
$logger->setLogLevel(LogLevel::WARNING);

// Add context to a Web request.
$log->info('Web request initiated', ['method' => 'GET', 'endpoint' => 'user/account', 'queryParameters' => 'id=1234']);

// Add context to a disk space warning.
$log->warning('Free space is below safe threshold.', ['volume' => '/var/log', 'availablePercent' => 4]);

catch (\Exception $e) {
    $logger->error('Something exceptional has happened', ['exception' => $e]);
}

// Constructor Parameter
$channel = 'router';
$logger  = new Logger($channel);

// Setter method
$logger->setChannel('database');
bash
$ composer