Download the PHP package yii1tech/psr-log without Composer
On this page you can find all versions of the php package yii1tech/psr-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package psr-log
Yii1 PSR Log Extension
This extension allows integration with PSR compatible logger for Yii1. Its usage in particular it allows usage of Monolog logger.
For license information check the LICENSE-file.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the "require" section of your composer.json.
Usage
This extension allows integration with PSR compatible logger for Yii1. It provides several instruments for that. Please choose the one suitable for your particular needs.
Wrap PSR logger into Yii logger
The most common use case for PSR logger involvement into Yii application is usage of 3rd party log library like Monolog.
This can be achieved using \yii1tech\psr\log\Logger instance as Yii logger. Its instance should be passed to \Yii::setLogger()
before the application instantiation.
Application entry script example:
\yii1tech\psr\log\Logger passes all messages logged via Yii::log() to the related PSR logger, which stores them according to its
own internal logic.
Also, usage of \yii1tech\psr\log\Logger grands you several additional benefits:
- It allows usage of
\Psr\log\LogLevelconstants for log level specification instead of\CLoggerones. - It allows passing log context as array as a 3rd argument of the
Yii::log()method, and saving it into Yii logs.
For example:
You may also specify a global log context, which should be written with every message. For example:
PSR Log Route
It is not necessary to \yii1tech\psr\log\Logger if you need to pass logs to PSR logger.
As an alternative you can add \yii1tech\psr\log\PsrLogRoute log route to the standard Yii "log" component.
Application configuration example:
Note: even if you use
\yii1tech\psr\log\Loggeras Yii logger, this\yii1tech\psr\log\PsrLogRoutewill be unable to handle passed log context correctly.
Wrap Yii logger into PSR logger
There is another use case related to PSR logger besides bootstrapping eternal log storage. Sometimes 3rd party libraries may require PSR logger instance to be passed to them in order to function. For example, imagine we have a 3rd party library for "daemon" application running:
You can use \yii1tech\psr\log\PsrLogger to wrap standard Yii logging mechanism into PSR interface.
Application configuration example:
Now while working with our example external "daemon" application, we can use following code:
Note: in order to handle log context properly
\yii1tech\psr\log\PsrLoggershould be used in junction with\yii1tech\psr\log\Logger.