Yii2 custom log file writing log

WBOY
Release: 2016-08-08 09:18:59
Original
2440 people have browsed it

Introduce the log class in the header
use yiilogFileTarget;


$time = microtime(true);
$log = new FileTarget();
$log->logFile = Yii::$app->getRuntimePath(). '/logs/zhidemy.com.log'; //Customized file name
$log->messages[] = ['test',1,'application',$time];
$log->export( );
This can basically be written. Let’s first look at the class description information of $log->message
/*
* [0] => message (mixed, can be a string or some complex data, such as an exception object)
* [1] => level (integer)
* [2] => category (string)
* [3] => timestamp (float, obtained by microtime(true))
* [ 4] => traces (array, debug backtrace, contains the application code call stacks)
*/
Just pass the parameters according to this information. Finally, remember an important point
$log->messages[] Don’t forget to add []
For details, please view the Target class

The above introduces the Yii2 custom log file writing log, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!