myena / default-logger
A simple PSR-3 compliant logger
Installs: 1 243
Dependents: 3
Suggesters: 1
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- bramus/ansi-php: 3.0.*
- psr/log: @stable
Requires (Dev)
- phpunit/phpunit: @stable
This package is auto-updated.
Last update: 2024-11-20 05:08:48 UTC
README
A simple PSR-3 compliant logger
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.