doulian8554
2019-03-06 13:00
浏览 213
已采纳

Yii2 - 在生产中记录500个错误

Im trying to debug an Internal Server Error on production that runs Yii2.

To do this, I added EmailTarget to my config file as follows

if(!YII_DEBUG){
    $logTarget[] = [
        'class' => 'yii\log\EmailTarget',
        'mailer' =>'mailer',
        'levels' => ['error'],
        'message' => [
            'from' => ['mail@example.com'],
            'to' => ['mymail@example.com'],
            'subject' => 'Log',
        ],
        'categories' => [
            'yii\db\*',
            'yii\web\HttpException:*',
        ],
        'except' => [
            'yii\web\HttpException:404',
            'yii\web\HttpException:403',
            'yii\web\HttpException:401'
        ]
    ];
}

then

    'log' => [
        'traceLevel' => 3,
        'targets' => $logTarget,
    ],

Im not getting the 500 errors though. Am I doing smt wrong? Or are 500 errors not logged by default

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtu7567 2019-03-08 11:18
    已采纳

    So finally got it working. Apparently, the 'categories' here blocked 500 errors from being sent probably since most 500 errors belong to yii\base\Excetion and not yii\web\HttpException. Since, by default, if no 'categories' are put, all the errors are included, just removing this from the array fixed the problem.

    My fixed array is:

    if(!YII_DEBUG){
        $logTarget[] = [
            'class' => 'yii\log\EmailTarget',
            'mailer' =>'mailer',
            'levels' => ['error'],
            'message' => [
                'from' => ['mail@example.com'],
                'to' => ['mymail@example.com'],
                'subject' => 'Log',
            ],
            'except' => [
                'yii\web\HttpException:404',
                'yii\web\HttpException:403',
                'yii\web\HttpException:401'
            ]
        ];
    }
    
    打赏 评论

相关推荐 更多相似问题