phapi/log

This package is abandoned and no longer maintained. No replacement package was suggested.

Phapi Log contains a Di container validator

1.0.0 2015-07-02 08:29 UTC

This package is not auto-updated.

Last update: 2021-02-05 22:35:07 UTC


README

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.