日志配置(在@config/web.php中):
‘log‘ => [ ‘traceLevel‘ => YII_DEBUG ? 3 : 0, ‘targets‘ => [ [ ‘class‘ => ‘yii\log\FileTarget‘, ‘levels‘ => [‘error‘, ‘warning‘], ], [ //日志记录方式 ‘class‘ => ‘yii\log\FileTarget‘, ‘levels‘ => [‘info‘],//日志等级 ‘logVars‘ =>[],//被收集记录的额外数据如 ‘logVars‘ => [‘_GET‘, ‘_POST‘, ‘_FILES‘, ‘_COOKIE‘, ‘_SESSION‘,‘_SERVER‘], //指定日志策略 ‘categories‘ => [‘MyLog‘], //指定日志目录 ‘logFile‘ => ‘@app/runtime/logs/Mylog/info.log‘, ‘maxFileSize‘ => 1024 * 2, ‘maxLogFiles‘ => 100, ], ], ],
日志写入方式之一:
Yii::getLogger()->log(print_r($post,true),yii\log\Logger::LEVEL_INFO,‘MyLog‘);//使用MyLog策略来记录info级别的日志
原文地址:http://quietnight.blog.51cto.com/7163892/1740140