标签:cat category 配置文件 div ... logfile 动态 error ali
如果我们在项目中不允许修改配置文件中的 log 组件,那么动态配置 log 就变得很重要了,下面我分享一下动态配置 log 的方法:
public function init()
{
parent::init();
Yii::$app->log->targets[0]->levels = [‘info‘, ‘error‘, ‘warning‘]; // only display info ,error and warning
Yii::$app->log->targets[0]->categories = [‘categoryName‘]; // log category
Yii::$app->log->targets[0]->logFile = Yii::getAlias(‘@app‘).DIRECTORY_SEPARATOR.‘runtime‘.DIRECTORY_SEPARATOR.‘logs‘.DIRECTORY_SEPARATOR.‘logFileName.log‘; // filePath
Yii::$app->log->targets[0]->logVars = [‘*‘]; // don‘t display GET,POST,SERVER,COOKIE,SESSION, if config this,display otherwise.
Yii::$app->log->targets[0]->maxFileSize = 1024 * 2; // maxFileSize=2M
Yii::$app->log->targets[0]->maxLogFiles = 20; // maxLogFiles = 20
...
}
`
标签:cat category 配置文件 div ... logfile 动态 error ali
原文地址:https://www.cnblogs.com/chrdai/p/9021053.html