PHP code example of markrogoyski / simplelog-php

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

    

markrogoyski / simplelog-php example snippets




$logfile = '/path/to/logfile.log';
$channel = 'events';
$logger  = new SimpleLog\Logger($logfile, $channel);

$logger->info('SimpleLog really is simple.');

$logfile = '/var/log/events.log';
$channel = 'billing';
$logger  = new SimpleLog\Logger($logfile, $channel);

$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;

// Optional constructor Parameter (Only error and above are logged [error, critical, alert, emergency])
$logger = new SimpleLog\Logger($logfile, $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 SimpleLog\Logger($logfile, $channel);

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

$logger->setOutput(true);
$logger->debug('This will get logged to STDOUT as well as the log file.');

use SimpleLog\Logger;

$logger->setLogLevel(Logger::LOG_LEVEL_NONE);
$logger->info('This will not log to a file.');
javascript
{
  "oyski/simplelog-php": "2.*"
  }
}
bash
$ php composer.phar install

$ php composer.phar