編程學習網 > PHP技術 > Yii2 > Yii2.0自定義日志文件寫日志
2016
01-27

Yii2.0自定義日志文件寫日志

頭部引入log類
use yii\log\FileTarget;


$time = microtime(true);
$log = new FileTarget();
$log->logFile = Yii::$app->getRuntimePath() . '/logs/zhidemy.com.log'; //文件名自定義
$log->messages[] = ['test',1,'application',$time];
$log->export();

這樣基本就能寫出來了,先看一下$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)
*/
傳遞參數按照這些信息進行傳遞就可以了。最后記住重要的一點
$log->messages[] 別忘了加[] 
具體可查看Target類

掃碼二維碼 獲取免費視頻學習資料

Python編程學習

查 看2022高級編程視頻教程免費獲取