Home  >  Article  >  Backend Development  >  Yii2 custom log file writing log

Yii2 custom log file writing log

WBOY
WBOYOriginal
2016-08-08 09:18:592440browse

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.

Statement:
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
Previous article:pinNext article:pin