Basic PSR-3 compliant logger.

v1.4 2021-12-22 17:09 UTC

This package is auto-updated.

Last update: 2023-02-22 19:45:31 UTC


Basic PSR-3 compliant logger implementation. See https://www.php-fig.org/psr/psr-3/


Use composer:

composer require unicate/logger


  • Use the constructor to pass the current loglevel.
  • The path to the log directory is optional. If not provided it will be logged to StdOut.
  • A filename including date pattern can also be passed optionally. Default is '{Y-m-d}-log.txt'.

require_once "vendor/autoload.php";

$logsDir = __DIR__ . '/../logs';

$logger = new \Unicate\Logger\Logger(LogLevel::ERROR, $logsDir, 'Appl-{Y-m-d}-test.txt');
  • Methods for each loglevel are implemented.
  • Data in {curly brackets} will be replaced with string in associative array and corresponding key.
$logger->debug('test some very detailed debug log {data}', ['data' => '...some data...']);
$logger->info('test loggin some info {kind} stuff', ['kind' => 'crazy']);
$logger->notice('Just for your notification.', []);
$logger->warning('Just be warned', []);
$logger->error('some error: {exception}', ['exception' => 'stack trace...']);
$logger->critical('A mission critical log entry!', ['exception' => 'Stack trace')]);
$logger->alert('Aleeeerrrrtt', []);
$logger->emergency('Its an Emergency', []);