PHP code example of pollen-solutions / log

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

    

pollen-solutions / log example snippets


use Pollen\Log\LogManager;

$log = new LogManager();

// Adds a log record at the DEBUG level
$log->debug('My debug message');

// Adds a log record at the INFO level
$log->debug('My info message');

// Adds a log record at the SUCCESS level
$log->success('My success message');

// Adds a log record at the NOTICE level
$log->notice('My notice message');

// Adds a log record at the WARNING level
$log->warning('My warning message');

// Adds a log record at the ERROR level
$log->error('My error message');

// Adds a log record at the CRITICAL level
$log->critical('My critical message');

// Adds a log record at the ALERT level
$log->alert('My alert message');

// Adds a log record at the EMERGENCY level
$log->emergency('My alert message');
 

use Pollen\Log\LogManager;

$log = (new LogManager())->setDefaultStoragePath('/var/log/myapp');

use Pollen\Log\Logger;
use Pollen\Log\LogManager;

$log = new LogManager();

$log->registerChannel('my-channel', [
       /** 
        * Log filename (relative or absolute).
        * @see \Monolog\Handler\RotatingFileHandler
        * @var string|null
        */
        'filename' => null,
       /** 
        * Rotation frequency.
        * @see \Monolog\Handler\RotatingFileHandler
        * @var int|null
        */
       'rotate' => null,
       /** 
        * Minimum logging level.
        * @see \Monolog\Handler\RotatingFileHandler
        * @var string|null
        */
        'level'  => Logger::SUCCESS,
       /** 
        * Line format.
        * @see \Monolog\Formatter\LineFormatter
        * @var string|null
        */
      'format' => null,
       /** 
        * Date format. 
        * @see \Monolog\Formatter\LineFormatter
        * @var string|null
        */
      'date_format' => null
]);

$log->channel('my-channel')->success('Test log success message');

use Monolog\Handler\NativeMailerHandler;
use Pollen\Log\Logger;
use Pollen\Log\LogManager;

$log = new LogManager();

$channel = new Logger(
    'mailer',
    [new NativeMailerHandler('[email protected]', 'You have a log report message !', '[email protected]')]
);

$log->addChannel($channel);

$log->channel('mailer')->error('Test log error message');