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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题