2017 © Pedro Peláez
 

library logging

RadPHP logging component

image

radphp/logging

RadPHP logging component

  • Friday, March 31, 2017
  • by atkrad
  • Repository
  • 2 Watchers
  • 7 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

RadPHP Logging Component

License Total Downloads, (*1)

The Logging library provides multiple logging adapters using a simple interface. With the Logger class it is possible to send a single message to multiple logging adapters at the same time., (*2)

By default you can use File or Null as logging adapters, but you can use any object implementing Rad\Logging\AdapterInterface as an adapter for the Logger class., (*3)

Usage

You can create new instance adapter and attached to the Logger class. An example would be:, (*4)

use Rad\Logging\Logger;
use Rad\Logging\Adapter\FileAdapter;

// Attach single or multiple adapters
$logger = new Logger();

$logger->attachAdapter(new NullAdapter());
$logger->attachAdapter(new FileAdapter('/path/to/file.log'));
// Or attaching your adapter
$logger->attachAdapter(new MyAdapter());

// You can pass message to these log levels
$logger->emergency('Something did not work');
$logger->alert('Something did not work');
$logger->critical('Something did not work');
$logger->error('Something did not work');
$logger->warning('Something did not work');
$logger->notice('Something did not work');
$logger->info('Something did not work');
$logger->debug('Something did not work');

The log output is below:, (*5)

09/Apr/2016 11:18:55 UTC [EMERGENCY] Something did not work
09/Apr/2016 11:18:55 UTC [ALERT] Something did not work
09/Apr/2016 11:18:55 UTC [CRITICAL] Something did not work
09/Apr/2016 11:18:55 UTC [ERROR] Something did not work
09/Apr/2016 11:18:55 UTC [WARNING] Something did not work
09/Apr/2016 11:18:55 UTC [NOTICE] Something did not work
09/Apr/2016 11:18:55 UTC [INFO] Something did not work
09/Apr/2016 11:18:55 UTC [DEBUG] Something did not work

The log message may contain placeholders. Placeholder names must correspond to keys in the context array. Placeholder names must be delimited with a single opening brace { and a single closing brace }. There must not be any whitespace between the delimiters and the placeholder name. Placeholder names should be composed only of the characters A-Z, a-z, 0-9, underscore _, and period .. The use of other characters is reserved for future modifications of the placeholders specification., (*6)

The following is an example uses placeholder in log message:, (*7)

use Rad\Logging\Logger;
use Rad\Logging\Adapter\FileAdapter;

$logger = new Logger();
$logger->attachAdapter(new FileAdapter('/path/to/file.log'));
$logger->info('User "{user_id}" successfully logged in.', ['user_id' => 2]);

Transactions

Transactions store log data temporarily in memory and later on write the data to all adapters., (*8)

use Rad\Logging\Logger;
use Rad\Logging\Adapter\FileAdapter;

$logger = new Logger();
$logger->attachAdapter(new FileAdapter('/path/to/file.log'));

$logger->begin();
try {
    //Code here
    $logger->commit();
} catch (\Exception $e) {
    $logger->rollback();
    throw $e;
}

Formatter

You can use formatter for format log lines or implementing your own formatter. Your formatter must be implemented Rad\Logging\FormatterInterface, Default formatter is LineFormatter, (*9)

use Rad\Logging\Logger;
use Rad\Logging\Adapter\FileAdapter;

$logger = new Logger();

$fileAdapter = new FileAdapter('/path/to/file.log');
$fileAdapter->setFormatter(new LineFormatter("%time% :: {%level%} :: %message%\n", 'G:i:s T'));
$logger->attachAdapter($fileAdapter);

$logger->emergency('Something did not work');
$logger->alert('Something did not work');

The log output with new format:, (*10)

11:18:55 UTC :: {EMERGENCY} :: Something did not work
11:18:55 UTC :: {ALERT} :: Something did not work

These variables available for LineFormatter:, (*11)

Variables Description
%time% Log time
%level% Log level
%message% Log message

The Versions

31/03 2017

0.2.x-dev

0.2.9999999.9999999-dev

RadPHP logging component

  Sources   Download

MIT

The Requires

 

by Omid Mottaghi Rad

component logging radphp

17/09 2016

dev-master

9999999-dev

RadPHP logging component

  Sources   Download

MIT

The Requires

 

by Omid Mottaghi Rad

component logging radphp

19/04 2016

v0.1.0

0.1.0.0

RadPHP logging component

  Sources   Download

MIT

The Requires

 

by Omid Mottaghi Rad

component logging radphp