Disable db profiler in Yii 2.0

Hi All,

I am trying to disable the db profiler on my production systems and I constantly get the below profiling information on my logs:

2015-06-25 10:13:54 [172.17.42.1][-][-][info][yii\db\Connection::open] Opening DB connection: mysql:host=172.18.64.142;dbname=live

2015-06-25 10:13:54 [172.17.42.1][-][-][profile begin][yii\db\Connection::open] Opening DB connection: mysql:host=172.18.64.142;dbname=live

2015-06-25 10:13:54 [172.17.42.1][-][-][profile end][yii\db\Connection::open] Opening DB connection: mysql:host=172.18.64.142;dbname=live

2015-06-25 10:13:54 [172.17.42.1][-][-][info][yii\db\Command::query] SELECT * FROM metrics_micro WHERE metrics_id=‘3’

2015-06-25 10:13:54 [172.17.42.1][-][-][profile begin][yii\db\Command::query] SELECT * FROM metrics_micro WHERE metrics_id=‘3’

2015-06-25 10:13:54 [172.17.42.1][-][-][profile end][yii\db\Command::query] SELECT * FROM metrics_micro WHERE metrics_id=‘3’

My logs are :

‘log’ => [

        'traceLevel' => YII_DEBUG ? 3 : 0,


        'targets' => [


            [


                'class'     => 'yii\log\FileTarget',


                'logFile'   => '@logs/app.log',


                'logVars'   => [],


            ],


            [


                'class'         => 'yii\log\FileTarget',


                'logFile'       => Yii::getAlias('@logs').'/cron.log',


                'logVars'       => [],


                'categories'    => ['cronjobs']


            ],


        ],


    ],

Even if I set YII_DEBUG to FALSE the profiling information still appears.

Is there a way to disable the db profiling?

-S.

Set ‘levels’ for the target with the categories you are interested in like ‘levels’ => [‘error’, ‘warning’],

Hi Bizley,

Thanks for the answer.

Even when I set ‘levels’ => [‘error’], in my target as you can see below:

        'targets' => [


            [


                'class'     => 'yii\log\FileTarget',


                'logFile'   => '@logs/app.log',


                'logVars'   => [],


                'levels'    => ['error','warning'],


                'prefix'    => function ($message){


                    $app_id     = \Yii::$app->id;


                    $container  = getenv('HOSTNAME');


                    $host_ip    = getenv('HOST_IP');


                    $build_id   = getenv('BUILD_ID');


                    $environment = getEnvVariable('APPENV_ID','local');


                    return "|$host_ip|$container|$build_id|$environment|$app_id";


                },


            ],

The dbprofiling data is still getting logged.

So this does not solve the issue.

There must be some other setting somewhere.

I’m not sure what can be the reason for this. Are you sure there is no module that is logging the queries? Or maybe db connection is configured to do this somehow?

You can check Yii::$app->getLog()->targets and see what’s there.

Hey - is this the case here? https://github.com/yiisoft/yii2/issues/1662