Skip to content

fix(logs): WDIO_LOG_LEVEL#10167

Merged
christian-bromann merged 2 commits intowebdriverio:mainfrom
KuznetsovRoman:fix/WDIO_LOG_LEVEL
Apr 12, 2023
Merged

fix(logs): WDIO_LOG_LEVEL#10167
christian-bromann merged 2 commits intowebdriverio:mainfrom
KuznetsovRoman:fix/WDIO_LOG_LEVEL

Conversation

@KuznetsovRoman
Copy link
Contributor

Proposed changes

  1. fix log output with set WDIO_LOG_LEVEL env variable.

Currently if you set WDIO_LOG_LEVEL env variable, you will still see info level logs from devtools and webdriver because devtools.newSession and webdriver.newSession defaulting logLevel to info (devtools and webdriver). Though its not needed because setLogLevelsConfig already sets right logLevels on wdio.remote here, and getLogger already has this fallback with default value.

  1. add documentation about WDIO_LOG_LEVEL env variable.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Reviewers: @webdriverio/project-committers


if (!options.logLevels || !options.logLevels.webdriver) {
logger.setLevel('webdriver', params.logLevel!)
if (params.logLevel && (!options.logLevels || !options.logLevels.webdriver)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in devtools

@KuznetsovRoman
Copy link
Contributor Author

one e2e test ("should allow to use then/catch/finally") randomly fell on windows due to test timeout.

*/
logLevel: {
type: 'string',
default: 'info',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the default values?

Copy link
Contributor Author

@KuznetsovRoman KuznetsovRoman Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned above, in "proposed changes". Summary: because they have a priority over WDIO_LOG_LEVEL and are obsolete: wdio/logger can handle default value on its own.

Currently if you set WDIO_LOG_LEVEL env variable, you will still see info level logs from devtools and webdriver because devtools.newSession and webdriver.newSession defaulting logLevel to info (devtools and webdriver). Though its not needed because setLogLevelsConfig already sets right logLevels on wdio.remote here, and getLogger already has this fallback with default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it does not affect the behavior if WDIO_LOG_LEVEL is not set, and will use logLevel= process.env.WDIO_LOG_LEVEL if it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this anyway as it better describes the default behavior. The default log level for @wdio/logger can maybe change in the future and we would like to keep the current default in devtools and webdriver.

Copy link
Contributor Author

@KuznetsovRoman KuznetsovRoman Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats about

    options.logLevel = process.env.WDIO_LOG_LEVEL ?? options.logLevel
    const params = validateConfig(DEFAULTS, options)

or

    const params = validateConfig(DEFAULTS, options)
    params.logLevel = process.env.WDIO_LOG_LEVEL?? options.logLevel ?? params.logLevel

in devtools/src/index.ts to set priority as:

  1. process.env.WDIO_LOG_LEVEL
  2. options.logLevel
  3. DEFAULT

Currently DEFAULT priority is higher than process.env.WDIO_LOG_LEVEL, which makes no sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me 👍

Copy link
Contributor Author

@KuznetsovRoman KuznetsovRoman Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

const envLogLevel = process.env.WDIO_LOG_LEVEL as Options.WebDriverLogTypes | undefined
options.logLevel = envLogLevel ?? options.logLevel
const params = validateConfig(DEFAULTS, options)

validateConfig is being called after setting logLevel from process.env so we could verify it

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thank you!

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Apr 12, 2023
@christian-bromann christian-bromann merged commit 1d95886 into webdriverio:main Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants