phpmake/logger

There is no license information available for the latest version (v0.1.0) of this package.

PSR-3 Logger implementation for handling PHP streams.

v0.1.0 2014-05-03 12:07 UTC

This package is not auto-updated.

Last update: 2020-03-20 16:17:30 UTC


README

PSR-3 Logger implementation for handling PHP streams.

API

Instantiate

default logger

Default logger outputs logs to stdout.

<?php
require_once 'PHPMake/Logger.php';
$defaultLogger = new \PHPMake\Logger();

Next line is equal to above.

$defaultLogger = new \PHPMake\Logger('php://stdout');

file appender

Constructor's first argument can be specified URL, then, logger outputs logs to the specified URL.

$fileAppender = new \PHPMake\Logger('file:///tmp/app.log');
// or
// $fileAppender = new \PHPMake\Logger('file:///tmp/app.log', 'a');

Constructor's second argument can be specified file opening mode. Default mode is a which means to 'append'.
If you passed w as second argument, specified file will be empty at first. Or passed r, you will get warnings when each output.

Logging

This logger implements \Psr\Log\Logger interface. Therefore, call these methods for logging.

$logger->debug('debug');
$logger->info('info');
$logger->notice('notice');
$logger->warning('warning');
$logger->error('error');
$logger->critical('critical');
$logger->alert('alert');
$logger->emergency('emergency');

threshold

setThreshold() method is provide to control outputs with log level.

$logger = new \PHPMake\Logger();
$logger->setThreshold(\Psr\Log\LogLevel::WARNING);

// debug, info and notice will not be output.
$logger->debug('debug');
$logger->info('info');
$logger->notice('notice');

// level which is warning or higher will be outputted.
$logger->warning('warning');
$logger->error('error');
$logger->critical('critical');
$logger->alert('alert');
$logger->emergency('emergency');