arrilot/logs

0.1 2017-07-08 11:48 UTC

This package is auto-updated.

Last update: 2024-09-21 01:04:43 UTC


README

Latest Stable Version Total Downloads Build Status Scrutinizer Quality Score

一个简单的特质,使得任何类都能使用PSR-3日志记录器。

安装

composer require arrilot/logs

使用方法

use Arrilot\Logs\Logs;

class Foo
{
    use Logs;

    function bar()
    {
        $this->logger()->error('Error happened in bar!);
        $this->logger()->warning('Warning happened in bar!);
        // etc
    }
}


$foo = new Foo();
$foo->bar(); // Everything is ok, but nothing was logged anywhere because no logger was set.

$foo->setLogger($anyPsr3LoggerHere);
$foo->bar(); // There is a log record in $anyPsr3LoggerHere now.

$foo->setEchoLogger();
$foo->bar(); // An error and a warning are echo'ed to a screen.

// If you are using Monolog\Registry to store loggers, you can simply pass a logger name and the package will grab a logger from the Registry.
$foo->setLogger('application_log');
$foo->bar(); // There is a record in application log.

您也可以使用 Arrilot\Logs\EchoLogger 作为独立的PSR-3日志记录器,而无需特质。