: This article describes how to write logs in custom log files of Yii2. For more information about PHP tutorials, see. Introduce the log class to the header
Use yii \ log \ FileTarget;
$ Time = microtime (true );
$ Log = new FileTarget ();
$ Log-> logFile = Yii: $ app-> getRuntimePath (). '/logs/zhidemy.com. log'; // custom file name
$ Log-> messages [] = ['test', 1, 'application', $ time];
$ Log-> export ();
In this way, the class description of $ log-> message can be written first.
/*
* [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)
*/
You can pass the parameters according to the information. Remember the important points
$ Log-> messages [] do not forget to add []
For details, refer to the Target class.
The above describes the log writing in The Yii2 custom log file, including the content, and hope to be helpful to friends who are interested in the PHP Tutorial.