日志在 yii2 中不起作用 [英] Log not working in yii2
本文介绍了日志在 yii2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 app.log 中添加一个日志,我的配置文件
i want to put a log in app.log ,My config file
'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('开始计算平均收入');不工作
} But Yii::trace('start calculating average revenue'); not working
推荐答案
尝试在控制台配置中将 flushInterval
和 exportInterval
都设置为 1:
Try to set both flushInterval
and exportInterval
to 1 in console config:
return [
'bootstrap' => ['log'],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'exportInterval' => 1,
],
],
'flushInterval' => 1,
],
],
];
它使每条日志消息立即出现在日志中.
It makes each log message appearing immediately in logs.
这篇关于日志在 yii2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文