Cms: Console command logs too much in production env

Created on 21 Nov 2019  路  6Comments  路  Source: craftcms/cms

Description

Even in production mode, commands running with the ./craft CLI command seems to output too much info into the console.log file, (e.g level profile, trace, info..).
This is bad for performance and will take up a lot of unnecessary space - at least if you run ./craft-commands as cronjobs.

https://github.com/craftcms/cms/blob/a0ed3fba32112907d84ab6c0b549d0e9f94026b0/bootstrap/bootstrap.php#L170-L184 :thinking:

Any reason devMode always should be on when running console commands?
Is there a way to turn this off or at least define what level it should log?

Steps to reproduce

  1. Install craft.
  2. Set ENVIRONMENT="production" in .env.
  3. Run ./craft help.
  4. Check storage/logs/console.log file too see output.

Additional info

  • Craft version: 3.3.15
  • PHP version: 7.2.24
  • Database driver & version: MySQL 5.7.28
  • Plugins & versions: N/A

All 6 comments

After chatting with @khalwat on discord we figured that levels could be configured something like this inside config/app.console.php:

<?php
use yii\log\Logger;

return [
    'components' => [
        'log' => function() {
            $config = craft\helpers\App::logConfig();
            if ($config) {
                $config['targets'][0]['levels'] = Logger::LEVEL_ERROR | Logger::LEVEL_WARNING;
                return Craft::createObject($config);
            }
            return null;
        },
    ],
];

but still curious if console-commands should run in devMode _and_ output this much by default? Seems a bit verbose.

Documented here at the end of the CUSTOMIZING THE EXISTING LOGGER section: Creating a Custom Logger for Craft CMS

Thanks for pointing this out. As of the next release, Craft will only log errors and warnings for console requests if Dev Mode isn鈥檛 enabled, just like web requests.

Looks like this wasn鈥檛 actually fully fixed, per #5479.

Really resolved now for the next 3.4 release.

3.4.1 is out now with the fix.

Was this page helpful?
0 / 5 - 0 ratings