【发布时间】:2016-10-05 10:40:34
【问题描述】:
我想在 app.log 中添加一个日志,我的配置文件
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
'logFile' => '@root/console/runtime/logs/app.log',
],
]
]
在控制器动作中
public function actionRankCalculation()
{
$allConest = Contest::find()->where('isActive = 1')->all();
Yii::trace('start calculating average revenue');
$response = [];
/** @var Contest $contest */
foreach ($allConest as $contest) {
$videoQuery = Video::find()->where('contest_id = ' . $contest->id);
$videoQuery->andWhere('isActive = 1');
$videoQuery->orderBy([
'global_likes' => SORT_DESC,
'id' => SORT_ASC,
]);
} 但是 Yii::trace('开始计算平均收益');不工作
【问题讨论】:
-
如果您的path alias 正确,请尝试
Yii::error('start calculating average revenue');它将生成日志文件或添加` `。 -
或添加
'levels' => ['error', 'warning', 'trace'],
标签: yii2