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

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'
            ]
        ];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网友们我该怎么办啊,急
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡
  • ¥20 基于MATLAB的TDOA