Reputation: 2499
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' => ['[email protected]'],
'to' => ['[email protected]'],
'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
Upvotes: 2
Views: 2000
Reputation: 2499
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' => ['[email protected]'],
'to' => ['[email protected]'],
'subject' => 'Log',
],
'except' => [
'yii\web\HttpException:404',
'yii\web\HttpException:403',
'yii\web\HttpException:401'
]
];
}
Upvotes: 1