myena/default-logger

A simple PSR-3 compliant logger

1.1.2 2018-03-11 22:58 UTC

This package is auto-updated.

Last update: 2024-02-20 03:34:50 UTC


README

A simple PSR-3 compliant logger

Build Status

Installation

This library is designed to be used with Composer

Require entry:

{
    "myena/default-logger": "@stable"
}

Basic Usage

$logger = new \MyENA\DefaultLogger();

$logger->debug('hello!');

Defaults

The default level of this logger is debug

The default stream for this logger is php://output

Custom Levels

You may specify custom levels one of two ways:

Construction:

$logger = new \MyENA\DefaultLogger(\Psr\Log\LogLevel::INFO);

Post-Construction:

$logger->setLogLevel(\Psr\Log\LogLevel::INFO);

If you attempt to specify a level not denoted by \Psr\Log\LogLevel, an exception will be thrown.

Custom Stream

If you wish for the log output to go to a file or some other resource writeable by the fwrite function, you may pass it in as the 2nd argument.

$logger = new \MyENA\DefaultLogger(\Psr\Log\LogLevel::DEBUG, fopen('tmp/test.log', 'ab'));

If this file becomes un-writeable for some reason, it will attempt to reconstruct the internal resource. If it is unable, it will revert to using the stream returned by the defaultStream().

NOTE: No write-ability determination is done, if you pass in a read-only stream it will ultimately not work.