PHP Classes

QuEasy PHP PSR Logger: Log messages to containers compliant with PSR-3

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-05-11 (6 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 20 All time: 10,443 This week: 259Up
Version License PHP version Categories
queasy-log 1.0Custom (specified...5PHP 5, Logging, PSR
Description Author

This package can log messages to containers compliant with PSR-3.

It provides a class that can take a configuration array to set a log container object of one class provided within this package.

Currently, it provides loggers classes to log messages to:

- Files
- Console terminal
- Email messages

Picture of Vitaly
  Performance   Level  
Name: Vitaly <contact>
Classes: 3 packages by
Country: Ukraine Ukraine
Age: 38
All time rank: 419674 in Ukraine Ukraine
Week rank: 245 Up2 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 1x

Details

Codacy Badge Build Status codecov Total Downloads License

Queasy PHP Framework - Logger

Package v-dem/queasy-log

Contains logger classes compatible with PSR-3 logger interface. Currently file system and console loggers are implemented. This package includes these types of logging:

  • Logger (base class, can be used as a container for other loggers)
  • FileSystemLogger
  • ConsoleLogger (supports ANSI color codes)
  • SimpleMailLogger (encapsulates `mail()` function)

Features

  • PSR-3 compatible.
  • Easy to use.
  • Easy to extend.
  • Nested loggers support.
  • Configurable output message format.

Requirements

  • PHP version 5.3 or higher

Documentation

See our Wiki page.

Installation

composer require v-dem/queasy-log:master-dev

Usage

Let's imagine we have the following config.php:

return [
    'logger' => [
        'class' => queasy\log\FileSystemLogger::class, // Logger class
        'processName' => 'test', // Process name, to differentiate log messages from different sources
        'minLevel' => Psr\Log\LogLevel::WARNING, // Message's minimum acceptable log level
        'path' => 'debug.log' // Path to logger output file
    ]
];

Creating logger instance

Include Composer autoloader:

require_once('vendor/autoload.php');

Create config instance (using v-dem/queasy-config package):

$config = new queasy\config\Config('config.php');

Or using arrays:

$config = include('config.php');

Create logger instance (in this case class option can be omitted and will be ignored):

$logger = new queasy\log\Logger($config);

Another way to create logger instance (it will create an instance of $config->logger->class, by default queasy\log\Logger as an aggregate logger will be used):

$logger = queasy\log\Logger::create($config);

> FileSystemLogger and ConsoleLogger have default settings and can be used without config. Default log file path for > FileSystemLogger is debug.log, default min log level is Psr\Log\LogLevel::DEBUG and max is LogLevel::EMERGENCY.

Writing messages to log

Output warning message:

$logger->warning('Test warning message.');

In debug.log you'll see something like this:

2017-12-24 16:13:09.302334 EET test [] [] [WARNING] Test warning message.

Chain log messages

$logger
    ->warning('going strange')
    ->error('cannot connect to the database')
    ->emergency('the website is down');

Using composite/nested loggers

config.php:

return [
    [
        'class' => queasy\log\FileSystemLogger::class,
        'path' => 'debug.full.log',
        'minLevel' => Psr\Log\LogLevel::DEBUG,
        [
            'class' => queasy\log\ConsoleLogger::class,
            'minLevel' => Psr\Log\LogLevel::INFO
        ], [
            'class' => queasy\log\SimpleMailLogger::class,
            'minLevel' => Psr\Log\LogLevel::ALERT,
            'mailTo' => 'john.doe@example.com',
            'subject' => 'Website Alert'
        ]
    ], [
        'class' => queasy\log\FileSystemLogger::class,
        'path' => 'debug.log',
        'minLevel' => Psr\Log\LogLevel::INFO
    ]
];

Usage:

$config = new queasy\config\Config('config.php');
$logger = new queasy\log\Logger($config);
$logger->info('Hello, world!');

Using date/time in log file name (note "%s" there, it will be replaced by current date and/or time formatted as described in timeLabel)

config.php:

return [
    [
        'class' => queasy\log\FileSystemLogger::class,
        'path' => 'debug-full.%s.log',
        'timeLabel' => 'Y-m-d',
        'minLevel' => Psr\Log\LogLevel::DEBUG
    ]
];
  Files folder image Files  
File Role Description
Files folder imagesrc (5 files)
Files folder imagetests (1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file codecov.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file ConsoleLogger.php Class Class source
  Accessible without login Plain text file FileSystemLogger.php Class Class source
  Accessible without login Plain text file InvalidArgumentException.php Class Class source
  Accessible without login Plain text file Logger.php Class Class source
  Accessible without login Plain text file SimpleMailLogger.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesrc (1 file)

  Files folder image Files  /  tests  /  src  
File Role Description
  Accessible without login Plain text file LoggerTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:20
This week:0
All time:10,443
This week:259Up
For more information send a message to info at phpclasses dot org.