2017 © Pedro Peláez
 

library log

Small log file writer with adjustable log level settings.

image

forestry/log

Small log file writer with adjustable log level settings.

  • Saturday, May 2, 2015
  • by daniel.melzer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Forestry Log

Latest Version Software License Build Status Codacy Badge Total Downloads, (*1)

Small log file writer with adjustable log level threshold settings., (*2)

Install

Via Composer, (*3)

``` bash $ composer require forestry/log, (*4)


## Usage ### Creating a logger ```php $logger = new Forestry\Log\Log('/tmp/dummy.log'); //Just log notices and above. $errorLog = new Forestry\Log\Log('./logs/error.log', Psr\Log\LogLevel::NOTICE);

Using a factory

Another way to create an instance is the use of one of the factories. There is one for each threshold level., (*5)

Here is an example for a logger with an error threshold:, (*6)

$factory = new ErrorLogger();
$logger = $factory->create('/tmp/error.log');

Log a message

Forestry\Log provides methods for the log levels defined by RFC 5424 (debug, info, notice, warning, error, critical, alert and emergency). There's a method for each of these levels:, (*7)

$logger->emergency('This is an emergency message');
$logger->alert('This is an alert message');
$logger->critical('This is an critical message');
$logger->error('This is an error message');
$logger->warning('This is an warning message');
$logger->notice('This is a notice message');
$logger->info('This is an information');
$logger->debug('This is a debug message');

You can also use a generic log method:, (*8)

$logger->log(Psr\Log\LogLevel::DEBUG, 'this is a debug message');

Using placeholders in log messages

You can use placeholders in the your message string and fill them using the associative context array. The array keys have to match the placeholders without the curly brackets:, (*9)

$user = array('name' => 'John Doe', 'mail' => 'j.doe@example.org');
$logger->info('Send mail to {name} ({mail})', $user); //Send mail to John Doe (j.doe@example.org)

Change the date format

The default date format is Y-m-d H:i:s. You can change it by using the setDateFormat method:, (*10)

$logger->setDateFormat('r'); //e.g. Thu, 21 Dec 2000 16:01:07 +0200

This method accepts any string which is compatible with PHPs native date()., (*11)

Change the message format

The default format for the log message is date level message. To change it, you can re-arrange the placeholders with setLogFormat:, (*12)

$logger->setLogFormat('[{level}|{date}] {message}'); //[INFO|2013-04-25 13:37:42] This is an info message

There are the following placeholder available:, (*13)

  • {date}
  • {level}
  • {message}

These placeholders will be replaced with ones for sprintf(), so you can also use the following:, (*14)

  • %1$s = date
  • %2$s = level
  • %3$s = message

Change the threshold level of an existing instance

To change the threshold level of an existing instance, use the setLogThreshold method:, (*15)

$logger->setLogThreshold(Psr\Log\LogLevel::DEBUG);

Get current logging level

To get the current threshold level of an existing instance, use the getLogThreshold method:, (*16)

$level = $logger->getLogThreshold();
$logger->setLogThreshold(Psr\Log\LogLevel::INFO);
$logger->logInfo('my info');
$logger->setLogThreshold($level);

Testing

bash $ phpunit, (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Credits

License

The MIT License (MIT). Please see License File for more information., (*19)

The Versions

02/05 2015

dev-master

9999999-dev https://github.com/ForestryCodes/log

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

 

log psr-3 logging forestry

02/05 2015

dev-develop

dev-develop https://github.com/ForestryCodes/log

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

 

log psr-3 logging forestry

02/05 2015

1.0.0

1.0.0.0 https://github.com/ForestryCodes/log

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

 

log psr-3 logging forestry

13/02 2015

0.3.0

0.3.0.0 https://github.com/ForestryCodes/log

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

 

log psr-3 logging forestry

02/02 2015

0.2.0.1

0.2.0.1 https://github.com/ForestryCodes/log

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

log forestry

23/09 2014

0.2.0

0.2.0.0

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

log logging

05/06 2013

0.1.0

0.1.0.0

Small log file writer with adjustable log level settings.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

log logging