Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii log skip 404 errors

Maybe exist solution to skip 404 exceptions ? I'mean not store this messages in log file ?

2015/04/09 12:28:52 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Невозможно обработать запрос "offer/downloadOffer".' in /var/www/yii/framework/web/CWebApplication.php:286
Stack trace:
#0 /var/www/yii/framework/web/CWebApplication.php(141): CWebApplication->runController('offer/downloadO...')
#1 /var/www/yii/framework/base/CApplication.php(184): CWebApplication->processRequest()
#2 /var/www/LAP/www/index.php(16): CApplication->run()
#3 {main}
REQUEST_URI=/offer/downloadOffer
like image 522
Wizard Avatar asked Apr 09 '15 08:04

Wizard


2 Answers

For Yii 2.0, you can make your config/main.php like this:

return [
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                    'except' => ['yii\web\HttpException:404'],
                ],
            ],
        ],
    ],
];
like image 120
Zhang Buzz Avatar answered Oct 06 '22 23:10

Zhang Buzz


For Yii 1.1, the correct way to exclude a category is to use the except key. Prepending a ! in the categories key as per the accepted answer will actually result in only matching categories that start with a !. So whilst it might appear to work, you're actually going to be suppressing all categories. See the filterAllCategories() function of the source code - there's no processing of the ! character, only for the * wildcard: GitHub Source.

I tried the !exception.CHttpException.404 approach in the accepted answer and thought I'd solved the issue of hiding the 404 errors, but then I realised after much hair pulling that this was resulted in no logs being logged!

The correct syntax to ignore a category is:

array(
   'class' => 'CFileLogRoute',
   'except' => 'exception.CHttpException.404'
)
like image 38
jt_uk Avatar answered Oct 07 '22 01:10

jt_uk