记录在yii2中不起作用

时间:2016-10-05 10:40:34

标签: yii2

我想在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('开始计算平均收入');不工作

2 个答案:

答案 0 :(得分:0)

尝试在控制台配置中将flushIntervalexportInterval都设置为1:

return [
    'bootstrap' => ['log'],
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'exportInterval' => 1,
                ],
            ],
            'flushInterval' => 1,
        ],
    ],
];

它使每个日志消息立即出现在日志中。

答案 1 :(得分:-1)

你试试这个。使用类别。例如下面的

            'targets' => [
           [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error'],
                 'categories' => ['test1'],
                'logFile' => '@app/Test/test1.log',


            ],

在控制器操作中使用下面的一个

 public function actionIndex(){    
   Yii::error('Test index action', $category = 'test1');   }