module-yii2 icon indicating copy to clipboard operation
module-yii2 copied to clipboard

No Yii2::debug() shown in the Codecept -vvv output

Open kublermdk opened this issue 5 months ago • 0 comments

What are you trying to achieve?

I would like to see the Yii2::debug() output in the codecept run -vvv <filename> output.

What do you get instead?

Only the Yii::info, Yii::warning and Yii::error outputs are shown.

Provide console output if related. Use -vvv mode for more details.


  [application] 'Info: Testing info Output in Codecept'
  [application] 'Warning: Testing Warning Output in Codecept'
  [application] 'Error: Testing Error Output in Codecept'

Provide test source code if related

    \Yii::trace("Trace: Testing Trace in Codecept");
    \Yii::debug("Debug: Testing Debugging in Codecept");
    \Yii::info("Info: Testing info Output in Codecept");
    \Yii::warning("Warning: Testing Warning Output in Codecept");
    \Yii::error("Error: Testing Error Output in Codecept");

Details

  • PHP Version: Tested with v7.4
  • Operating System: Linux
  • Installation type: Composer
  • Suite configuration:

class_name: UnitTester
modules:
    enabled:
      - Asserts
      - Filesystem
      - Yii2:
            part: [orm, email]

The issue can be resolved if I directly edit vendor/codeception/base/src/Codeception/Lib/Connector/Yii2/Logger.php and in the levels check

if (!in_array($level, [
    \yii\log\Logger::LEVEL_INFO,
    \yii\log\Logger::LEVEL_WARNING,
    \yii\log\Logger::LEVEL_ERROR,
])) {
    return;
}

I add in \yii\log\Logger::LEVEL_TRACE,

I suspect it's not in there because by default it would be rather verbose. Changing it now could also overwhelm existing users.

The reason I would like it in there is because when I'm debugging an issue and using Unit Tests to do so, it's nicer to use Yii::debug() for getting the information I need. I've spent ages setting up a unit test for a specific scenario only to find there's some edge case I need more info on to investigate. However I'm currently forced to use \Yii::info() to output that information and that is also output in the web debugger and in our staging environment log files and breaks the semantics of debug versus info

Ideally the Trace level would ONLY be included if -vvv (3x verbosity) was used and not -vv (2x verbosity) or if --debug.

However I'm not sure how to test that when the Logger->log() method is being called, so whilst I can submit a pull request simply adding the extra level, I suspect that's not ideal for existing users who might not want the extra verbosity.

Alternatively if someone can point out how I can specify my own logger so I can fork the existing one (or use container definitions to remap to my own)? Or allow it to only show if there's a config entry, like as part of the Yii2 module .yml, then that would be ideal.

kublermdk avatar Jan 24 '24 07:01 kublermdk