Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kublermdk opened this issue Jan 24, 2024 · 0 comments
Open

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

kublermdk opened this issue Jan 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kublermdk
Copy link

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.

@samdark samdark added the bug Something isn't working label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants