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

Add command-line flag to enable logs in tests #96

Open
gavv opened this issue May 22, 2023 · 2 comments
Open

Add command-line flag to enable logs in tests #96

gavv opened this issue May 22, 2023 · 2 comments
Labels
good first issue Good for newcomers help wanted Contributions are welcome tests Improvements or additions to tests

Comments

@gavv
Copy link
Member

gavv commented May 22, 2023

Currently, logging to console is disabled in tests. This is achieved by to measures:

  • log_test.go defines defaultLogLevel LogLevel = LogError; all tests that temporary enable logs, restore log level to this value; this level prevents all log messages except errors

  • main_test.go invokes log.SetOutput(ioutil.Discard); all tests that temporary redirect logs, restore log output to ioutil.Discard; this prevents logs to be written to console

However, for debugging, it may be useful to enable console logging.

We can do the following:

  • make defaultLogLevel a variable (default is still LogError)
  • add new global variable defaultLogOutput (default is ioutil.Discard)
  • add command-line flag to tests that enables logs; when the flag is set, defaultLogLevel is set to LogDebug, and defaultLogOutput to console
  • at start, tests should set log level and output to defaultLogLevel and defaultLogOutput
  • find all tests that call log.SetOutput(ioutil.Discard), and instead use log.SetOutput(defaultLogOutput)

Also, I think it makes sense to rename defaultLogLevel and defaultLogOutput to defaultTestLogLevel and defaultTestLogOutput.

@gavv gavv added help wanted Contributions are welcome tests Improvements or additions to tests good first issue Good for newcomers labels May 22, 2023
@gavv gavv mentioned this issue May 22, 2023
4 tasks
@vraj9845
Copy link

@gavv can I please try this?

@gavv
Copy link
Member Author

gavv commented May 23, 2023

Sure, thanks!

@vraj9845 vraj9845 removed their assignment Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions are welcome tests Improvements or additions to tests
Projects
None yet
Development

No branches or pull requests

2 participants