2017 © Pedro Peláez
 

library simplelogger

PHP write logs

image

firehed/simplelogger

PHP write logs

  • Tuesday, April 3, 2018
  • by Firehed
  • Repository
  • 1 Watchers
  • 0 Stars
  • 141 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

SimpleLogger

Build Status Coverage Status, (*1)

SimpleLogger is a PHP library to write logs., (*2)

  • Drivers: Syslog, stdout, stderr and text file
  • Compatible with PSR-3 Standard Logger Interface
  • Requirements: PHP >= 7.1
  • Author: Frédéric Guillot, Eric Stern
  • License: MIT

This is a fork from Frédéric Guillot's original SimpleLogger package, which has since been abandoned. I intend to actively maintain this as needed., (*3)

Usage

Installation

composer require firehed/simplelogger @stable

Syslog

Send log messages to Syslog:, (*4)

<?php

require 'vendor/autoload.php';

// Setup Syslog logging
$logger = new Firehed\SimpleLogger\Syslog('myapp');

// Output to syslog: "Jun  2 15:55:09 hostname myapp[2712]: foobar"
$logger->error('foobar');

// Output to syslog: "Jun  2 15:55:09 hostname myapp[2712]: Error at /Users/Me/Devel/libraries/simpleLogger/example.php at line 15"
$logger->error('Error at {filename} at line {line}', ['filename' => __FILE__, 'line' => __LINE__]);

Stdout

$logger = new \Firehed\SimpleLogger\Stdout();
$logger->error('foobar');

Stderr

$logger = new \Firehed\SimpleLogger\Stderr();
$logger->info('foobar');

Text file

Send log messages to a text file:, (*5)

<?php

require 'vendor/autoload.php';

// Setup File logging
$logger = new Firehed\SimpleLogger\File('/tmp/simplelogger.log');

// Output to the file: "[2013-06-02 16:03:28] [info] foobar"
$logger->info('foobar');

// Output to the file: "[2013-06-02 16:03:28] [error] Error at /Users/fred/Devel/libraries/simpleLogger/example.php at line 24"
$logger->error('Error at {filename} at line {line}', array('filename' => __FILE__, 'line' => __LINE__));

// Dump a variable
$values = array(
    'key' => 'value'
);

// Output: [2013-06-02 16:05:32] [debug] array (
//  'key' => 'value',
// )
$logger->dump($values);

Multiple loggers

Send log messages to multiple loggers:, (*6)

<?php

require 'vendor/autoload.php';

$logger = new Firehed\SimpleLogger\ChainLogger;
$logger->addLogger(new Firehed\SimpleLogger\Syslog('myapp'));
$logger->addLogger(new Firehed\SimpleLogger\File('/tmp/simplelogger.log'));

$logger->info('my message');
$logger->error('my error message');
$logger->error('my error message with a {variable}', ['variable' => 'test']);

Minimum log level for loggers

In this example, only messages with the level >= "error" will be sent to the Syslog handler but everything is sent to the File handler:, (*7)

<?php

require 'vendor/autoload.php';

$syslog = new Firehed\SimpleLogger\Syslog('myapp');
$syslog->setLevel(Psr\Log\LogLevel::ERROR);  // Define the minimum log level

$file = new Firehed\SimpleLogger\File('/tmp/simplelogger.log');

$logger = new Firehed\SimpleLogger\ChainLogger;
$logger->addLogger($syslog);
$logger->addLogger($file);

$logger->debug('debug info sent only to the text file');
$logger->error('my error message');
$logger->error('my error message with a {variable}', array('variable' => 'test'));

The minimum log level is LogLevel::DEBUG by default., (*8)

The Versions

03/04 2018
07/05 2016

v1.0.1

1.0.1.0 https://github.com/fguillot/simpleLogger

PHP library to write logs (compatible with PSR-3)

  Sources   Download

MIT

The Requires

 

29/08 2015

v1.0.0

1.0.0.0 https://github.com/fguillot/simpleLogger

PHP library to write logs (compatible with PSR-3)

  Sources   Download

MIT

The Requires

 

30/05 2015

v0.0.2

0.0.2.0 https://github.com/fguillot/simpleLogger

PHP library to write logs (compatible with PSR-3)

  Sources   Download

MIT

The Requires

 

02/01 2015

v0.0.1

0.0.1.0 https://github.com/fguillot/simpleLogger

PHP library to write logs (compatible with PSR-3)

  Sources   Download

MIT

The Requires