I've noticed that Craft 3 log files in storage/logs e.g. web-404s.log and web.log don't seem to have a max size or rotate like with Craft 2.

The web-404s.log file is nearly 10 megs for 1 site now.

Should the log files continually grow like this or is there just an issue with my setup?

Are there config settings to set the max log file size or disable certain logging that I'm missing?

Thanks

up vote 1 down vote accepted

Craft goes with Yii 2's defaults in the FileTarget class, which is 10MB for a log file before rotating. https://www.yiiframework.com/doc/api/2.0/yii-log-filetarget#$maxFileSize-detail

You can overwrite that behavior from your config/app.php file by using something like:

'components' => [
        'log' => function() {
            $log = Craft::createObject([
                'class' => yii\log\Dispatcher::class,
                'targets' => [
                    [
                        'class' => craft\log\FileTarget::class,
                        'levels' => !YII_DEBUG ? yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING : yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING | yii\log\Logger::LEVEL_INFO | yii\log\Logger::LEVEL_TRACE | yii\log\Logger::LEVEL_PROFILE,
                        'maxFileSize' => 5120, // 5MB
                    ],
                ],
            ]);

            return $log;
        },
    ],
  • Great - many thanks for this info. Is it possible to disable the 404 logging altogether? – Tidy Oct 22 at 8:55
  • A plugin/module that used it's own ErrorHandler or FileTarget class could get away with it. – Brad Bell Oct 22 at 17:16

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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