2017 © Pedro Peláez
 

library php-logger

Simple and fast php logging library

image

mougrim/php-logger

Simple and fast php logging library

  • Wednesday, September 13, 2017
  • by Mougrim
  • Repository
  • 2 Watchers
  • 3 Stars
  • 169 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

Repository is archived

If you want to maintain it, you can make a fork., (*1)

php-logger

This is a fork of Apache log4php logging library., (*2)

Main theme - light and fast library, with simple configuring., (*3)

If you want use classes without namespaces, see mougrim/php-logger-old-interface., (*4)

See changelog and upgrade instructions., (*5)

Latest Stable Version Latest Unstable Version License Build Status Test Coverage, (*6)

Configuration

use Mougrim\Logger\Appender\AppenderStream;
use Mougrim\Logger\Layout\LayoutPattern;
use Mougrim\Logger\Layout\LayoutSimple;
use Mougrim\Logger\Logger;

Logger::configure([
    'policy' => [
        'ioError' => 'trigger_error', // ignore, trigger_warn, trigger_error, exception or exit
        'configurationError' => 'exception'
    ],
    'layouts' => [
        'simple' => [
            'class' => LayoutSimple::class,
        ],
        'pattern' => [
            'class' => LayoutPattern::class,
            'pattern' => '{date:Y/m/d} [{level}] {logger} {location:file:line, class.function} {mdc:key} {mdc} {ndc}: {message} {ex}',
        ],
    ],
    'appenders' => [
        'stream' => [
            'class' => AppenderStream::class,
            'stream' => 'php://stdout',
            // pass useLock and useLockShortMessage true for enable lock
            'useLock' => false,
            'useLockShortMessage' => false,
            'minLevel' => Logger::DEBUG,
            'maxLevel' => Logger::FATAL,
            'layout' => 'simple',
        ],
    ],
    'loggers' => [
        'logger' => [
            'appenders' => ['stream'],
            'addictive' => false,
            'minLevel' => Logger::TRACE,
            'maxLevel' => Logger::FATAL,
        ],
    ],
    'root' => [
        'appenders' => ['stream'],
    ]
]);

Logging

Logger::getLogger('logger')->trace("hello world");
Logger::getLogger('logger')->debug("hello world");
Logger::getLogger('logger')->info("hello world");
Logger::getLogger('logger')->warn("hello world");
Logger::getLogger('logger')->fatal("hello world");
Logger::getLogger('logger')->log(Logger::DEBUG, "hello world");

Mapped Diagnostic Context, mdc

LoggerMDC::put("request", $i++);
Logger::getLogger('accesslog')->info("new request");
Logger::getLogger('db')->info("execute sql");

# in some web log : cat log | grep 12412
accesslog [request=12412] new request
db [request=12412] execute sql

Timer

$logger = Logger::getLogger('db');
$timer = $logger->timer();
$pdo->exec('select * from foo');
$timer->info("sql executed at {time}"); // rendered at

Thanks

Thanks to mitallast for the development of the main part of this project., (*7)

The Versions

13/09 2017

dev-master

9999999-dev

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar Mougrim
by Avatar mitallast

13/09 2017

dev-updateSoftMocks

dev-updateSoftMocks

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar Mougrim
by Avatar mitallast

11/09 2017

dev-fixCodeStyle

dev-fixCodeStyle

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar Mougrim
by Avatar mitallast

03/09 2015

v2.0.0

2.0.0.0

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar Mougrim
by Avatar mitallast

25/11 2013

1.0.2

1.0.2.0

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.2.7

 

The Development Requires

by Avatar mitallast

25/11 2013

1.0.1

1.0.1.0

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.2.7

 

The Development Requires

by Avatar mitallast

25/11 2013

1.0.0

1.0.0.0

Simple and fast php logging library

  Sources   Download

MIT

The Requires

  • php >=5.2.7

 

The Development Requires

by Avatar mitallast