Home >Backend Development >PHP Tutorial >Yii2.0 Chinese Development Wizard - Custom log file writing log, yii2.0 log file_PHP tutorial
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. First, take a 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 the important point
$log->messages[] Don’t forget to add []
For details, please view the Target class