zire/psr-log

日志库的通用接口

维护者

详细信息

github.com/phptux/log

主页

源码

1.2.0 2021-01-05 19:31 UTC

This package is auto-updated.

Last update: 2024-09-06 03:26:30 UTC


README

此仓库包含与PSR-3相关的所有接口/类/特性。

请注意,这并不是一个自带的日志记录器。它只是一个描述日志记录器接口的接口。更多详细信息请参阅规范。

安装

composer require zire/psr-log

用法

如果您需要日志记录器,您可以使用接口如下

<?php

use Psr\Log\LoggerInterface;

class Foo
{
    private $logger;

    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger;
    }

    public function doSomething()
    {
        if ($this->logger) {
            $this->logger->info('Doing work');
        }
           
        try {
            $this->doSomethingElse();
        } catch (Exception $exception) {
            $this->logger->error('Oh no!', array('exception' => $exception));
        }

        // do something useful
    }
}

然后您可以选择实现该接口的其中一个实现来获取日志记录器。

如果您想实现该接口,可以在您的代码中引入此包并实现Psr\Log\LoggerInterface。更多详细信息请参阅规范文本