2017 © Pedro Peláez
 

library queasy-log

Logger classes (currently supports file system and console logging), part of Queasy PHP Framework

image

v-dem/queasy-log

Logger classes (currently supports file system and console logging), part of Queasy PHP Framework

  • Sunday, July 29, 2018
  • by vdem
  • Repository
  • 1 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 3 Open issues
  • 1 Versions
  • 11 % Grown

The README.md

28X)" /> , (*1)

Codacy Badge codecov Total Downloads Latest Stable Version License, (*2)

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:, (*3)

  • 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., (*4)

Installation

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

Usage

Let's imagine we have the following config.php:, (*5)

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:, (*6)

require_once('vendor/autoload.php');

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

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

Or using arrays:, (*8)

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

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

$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):, (*10)

$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., (*11)

Writing messages to log

Output warning message:, (*12)

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

In debug.log you'll see something like this:, (*13)

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:, (*14)

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:, (*15)

$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:, (*16)

return [
    [
        'class' => queasy\log\FileSystemLogger::class,
        'path' => 'debug-full.%s.log',
        'timeLabel' => 'Y-m-d',
        'minLevel' => Psr\Log\LogLevel::DEBUG
    ]
];

The Versions

29/07 2018

dev-master

9999999-dev https://github.com/v-dem/queasy-log/

Logger classes (currently supports file system and console logging), part of Queasy PHP Framework

  Sources   Download

LGPL-3.0 LGPL-3.0-only

The Requires

 

The Development Requires

by Vitaly Demyanenko

logger log psr-3 php logging