2

We're currently logging our site at LEVEL_INFO to have a good idea of what's happening on the site. We find it useful, and appropriate, to log informational messages at that level rather than at ERROR or WARNING. However most of these INFO messages are drowned out by the sheer volume of SQL query logging. I did some digging and found that Yii DB Connections can be configured to not log all the queries.

https://github.com/yiisoft/yii2/blob/ec089fea5a684de1e358995bf36522ec6834e71b/framework/db/Connection.php#L410

This setting is then checked here: https://github.com/yiisoft/yii2/blob/bdb7c6491061b48c16b0fdbcba791ccd514a91d9/framework/db/Command.php#L1112

Ideally we'd like to be able to log queries at the TRACE or DEBUG level but it doesn't look to be possible.

Is there a simple way to disable the logging in the craft config? If not Would it be possible by extending an existing Craft class?

Any pointers or help would be appreciated. Thanks in advance!

2 Answers 2

1

This is what we ended up using.

<?php
    return [
        'components' => [
            'log' => [
                'targets' => [
                    [
                        'class' => PsrTarget::class,
                        'logger' => $logger,
                        'levels' => [YiiLogger::LEVEL_ERROR],
                        'logVars' => [],
                        'addTimestampToContext' => true,
                    ],
                    // Split the targets to specifically exclude classes which spam the logs, while
                    // ensuring errors thrown in those classes are still logged.
                    [
                        'class' => PsrTarget::class,
                        'logger' => $logger,
                        'levels' => $logLevels,
                        'except' => [
                            'yii\base\View::renderFile',
                            'yii\db\Command::*',
                            'yii\db\Connection::*'
                        ],
                        'logVars' => [],
                        'addTimestampToContext' => true,
                    ],
                ],
            ],
        ],
    ];
0

You can extend the default database component (including the Connection class) via config/app.php like so: https://docs.craftcms.com/v3/config/app.html#database-component

In your case, it should just be:

<?php
return [
    'components' => [
        'redis' => [
            'class' => craft\db\Connection::class,
            'enableLogging' => false
        ],
    ],
];
1
  • Thanks for the help but it didn't end up working for us. Commented Mar 3, 2020 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.