Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

phapi/log

Repository files navigation

Phapi Log

Build status Code Climate Test Coverage

Package contains a Di Container Validator for validating loggers.

Configuration

Loggers must be PSR-3 compatible. If no logger is configured or if the configured logger doesn't comply with PSR-3 then the NullLogger that is supplied in the PSR-3 package will be used.

In this example we will configure and use Monolog and set up a simple logger that logs to a file.

First, add the needed dependency to composer.json:

$ composer require monolog/monolog:1.*

After that it's just a matter of updating the configuration:

<?php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$container['log'] = function ($container) {
    $log = new Logger('default');

    // IMPORTANT! Make sure you use an absolute path. Relative paths aren't guaranteed to
    // work in cases where errors and exceptions occur.
    $log->pushHandler(new StreamHandler(__DIR__ . '/../logs/logfile.log', Logger::WARNING));
    return $log;
};

Usage

<?php
// add records to the log
$container['log']->warning('Foo');
$container['log']->error('Bar');

License

Phapi Log is licensed under the MIT License - see the license.md file for details

Contribute

Contribution, bug fixes etc are always welcome.