承接 alexeevdv/yii2-psr-log-adapter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alexeevdv/yii2-psr-log-adapter

最新稳定版本:1.0.1

Composer 安装命令:

composer require alexeevdv/yii2-psr-log-adapter

包简介

README 文档

README

Build Status codecov PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2 PHP 7.3

Yii2 logger is not PSR3 compatible, therefore when you need logger functionality in third party library (which uses PSR3 logger interface), this package may save your time.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require alexeevdv/yii2-psr-log-adapter

or add

"alexeevdv/yii2-psr-log-adapter": "^1.0"

to the require section of your composer.json file.

Usage

Lets assume some third party code

use Psr\Log\LoggerInterface;

class ThirdParty 
{
    private $logger;

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

Create adapter implicitly

use alexeevdv\yii\PsrLoggerAdapter;

$logger = new PsrLoggerAdapter(['category' => 'my-category']);
$thirdParty = new ThirdParty($logger);

Transparent usage via DI container

// Yii application config
[
    //...
    'container' => [
        'definitions' => [
            \Psr\Log\LoggerInterface::class => [
                'class' => \alexeevdv\yii\PsrLoggerAdapter::class,
                'category' => 'my-category',
            ],
        ],
    ],
    //...
]

// Lest create third party object now
// Logger adapter will be injected automagically
$thirdParty = Yii::createObject(ThirdParty::class);

Configuration

By default yii logger is taken from DI container but you can specify your own if you wish.

use alexeevdv\yii\PsrLoggerAdapter;

$logger = new PsrLoggerAdapter([
    'logger' => 'mylogger', // logger configuration here. Anything that can be passed to \yii\di\Instance::ensure
    'category' => 'my-category',
]);

统计信息

  • 总下载量: 10.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-14