PHP code example of liberta / logger

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

    

liberta / logger example snippets

 php


[
    [
        'name' => 'Paul Coiffier',
        'username' => 'pcoiffier',
    ],
    [
        'name' => 'Audrey Dupont',
        'username' => 'adupont',
    ],
];

$logger = new Liberta\Logger\Logger(__DIR__.'/logs');
$logger->info('Returned a million search results');
$logger->error('Oh dear.');
$logger->debug('Got these users from the Database.', $users);

[2014-03-20 3:35:43.762437] [INFO] Returned a million search results
[2014-03-20 3:35:43.762578] [ERROR] Oh dear.
[2014-03-20 3:35:43.762795] [DEBUG] Got these users from the Database.
    0: array(
        'name' => 'Paul Coiffier',
        'username' => 'coiffierp',
    )
    1: array(
        'name' => 'Michel Dupont',
        'username' => 'mdup',
    )
 php

use Psr\Log\LogLevel;

// These are in order of highest priority to lowest.
LogLevel::EMERGENCY;
LogLevel::ALERT;
LogLevel::CRITICAL;
LogLevel::ERROR;
LogLevel::WARNING;
LogLevel::NOTICE;
LogLevel::INFO;
LogLevel::DEBUG;
 php

// The 
$logger = new Liberta\Logger\Logger('/var/log/', Psr\Log\LogLevel::WARNING);
$logger->error('Uh Oh!'); // Will be logged
$logger->info('Something Happened Here'); // Will be NOT logged
 php

// Example
$logger = new Liberta\Llogger\Logger('/var/log/', Psr\Log\LogLevel::WARNING, array (
    'extension' => 'log', // changes the log file extension
));