Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexeevdv/yii2-psr-log-adapter
https://github.com/alexeevdv/yii2-psr-log-adapter
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/alexeevdv/yii2-psr-log-adapter
- Owner: alexeevdv
- License: mit
- Created: 2018-07-13T18:43:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-19T17:53:44.000Z (almost 6 years ago)
- Last Synced: 2024-11-22T16:30:17.979Z (about 2 months ago)
- Language: PHP
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PSR3 log adapter for Yii2 logger
[![Build Status](https://travis-ci.org/alexeevdv/yii2-psr-log-adapter.svg?branch=master)](https://travis-ci.org/alexeevdv/yii2-psr-log-adapter)
[![codecov](https://codecov.io/gh/alexeevdv/yii2-psr-log-adapter/branch/master/graph/badge.svg)](https://codecov.io/gh/alexeevdv/yii2-psr-log-adapter)
![PHP 5.6](https://img.shields.io/badge/PHP-5.6-green.svg)
![PHP 7.0](https://img.shields.io/badge/PHP-7.0-green.svg)
![PHP 7.1](https://img.shields.io/badge/PHP-7.1-green.svg)
![PHP 7.2](https://img.shields.io/badge/PHP-7.2-green.svg)
![PHP 7.3](https://img.shields.io/badge/PHP-7.3-green.svg)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](https://getcomposer.org/download/).
Either run
```bash
$ 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
```php
use Psr\Log\LoggerInterface;class ThirdParty
{
private $logger;function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
}
```### Create adapter implicitly
```php
use alexeevdv\yii\PsrLoggerAdapter;$logger = new PsrLoggerAdapter(['category' => 'my-category']);
$thirdParty = new ThirdParty($logger);
```### Transparent usage via DI container
```php
// 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.```php
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',
]);
```