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

Align logging usage to python logging best practices #245

Closed
wants to merge 21 commits into from

Conversation

dariopnc
Copy link
Contributor

@dariopnc dariopnc commented Oct 11, 2021

Ref: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

In detail:

  • completely rewrote logger.py to only consider the WDM_LOG_LEVEL environment variable
  • modified every call to the logging function to adapt to the new structure
  • removed unused log_level parameter for Driver object init methods

Downsides:

  • Lost the abilty to set a fixed formatter for our logs
  • Lost the difference in logging levels between microsoft drivers and the others
  • Lost backward compatibilty for direct call to Driver object and its children

These downsides can be addressed by the module user, which is now able to properly control logs

Fixes #209
Closes #210
Fixes #277
Fixes #287

Dario Panico added 2 commits October 11, 2021 14:56
In detail:
- completely rewrote logger.py to only consider the WDM_LOG_LEVEL environment variable
- modified every call to the logging function to adapt to the new structure
- didn't change init methods to be backwards-compatible (log_level parameter is ignored) and added comments explaining it

Downsides:
- Lost the abilty to set a fixed formatter for our logs
- Lost the difference in logging levels between microsoft drivers and the others

But these downsides can be addressed by the module user, which is now able to properly control logs
@pep8speaks
Copy link

pep8speaks commented Oct 11, 2021

Hello @dariopnc! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 31:80: E501 line too long (98 > 79 characters)

Line 66:80: E501 line too long (106 > 79 characters)
Line 111:80: E501 line too long (93 > 79 characters)
Line 123:80: E501 line too long (85 > 79 characters)
Line 201:80: E501 line too long (80 > 79 characters)
Line 320:56: E231 missing whitespace after ','
Line 320:67: E231 missing whitespace after ','
Line 320:80: E501 line too long (88 > 79 characters)

Line 81:80: E501 line too long (104 > 79 characters)

Line 19:80: E501 line too long (91 > 79 characters)

Line 6:1: E302 expected 2 blank lines, found 1
Line 12:1: W293 blank line contains whitespace
Line 13:1: E305 expected 2 blank lines after class or function definition, found 1

Line 9:80: E501 line too long (82 > 79 characters)

Line 218:69: E231 missing whitespace after ','
Line 218:80: E501 line too long (95 > 79 characters)
Line 218:82: E231 missing whitespace after ','
Line 220:47: E231 missing whitespace after ','
Line 220:60: E231 missing whitespace after ','

Comment last updated at 2022-03-31 07:11:36 UTC

@aleksandr-kotlyar
Copy link
Collaborator

aleksandr-kotlyar commented Oct 15, 2021

@dariopnc some tests have been failed cause of "first line" argument.
https://github.com/SergeyPirogov/webdriver_manager/pull/245/checks?check_run_id=3859523313

fail example screenshot

image

… parameter in logging calls.

With the current master version you could have specified the first_line paramter during every logging call, but that would have been ignored for every call other than the one printing the actual first lines.
With this version you don't need to specify that parameter at every logging call other than that one.
@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2021

Codecov Report

Merging #245 (8b74525) into master (259cfdb) will decrease coverage by 0.34%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
- Coverage   93.09%   92.75%   -0.35%     
==========================================
  Files          11       11              
  Lines         478      469       -9     
  Branches       68       66       -2     
==========================================
- Hits          445      435      -10     
- Misses         17       18       +1     
  Partials       16       16              
Impacted Files Coverage Δ
webdriver_manager/chrome.py 100.00% <100.00%> (ø)
webdriver_manager/driver.py 97.50% <100.00%> (ø)
webdriver_manager/driver_cache.py 93.50% <100.00%> (ø)
webdriver_manager/firefox.py 100.00% <100.00%> (ø)
webdriver_manager/logger.py 77.77% <100.00%> (-16.96%) ⬇️
webdriver_manager/manager.py 100.00% <100.00%> (ø)
webdriver_manager/microsoft.py 100.00% <100.00%> (ø)
webdriver_manager/opera.py 88.88% <100.00%> (-0.59%) ⬇️
webdriver_manager/utils.py 91.66% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 259cfdb...8b74525. Read the comment docs.

@aleksandr-kotlyar
Copy link
Collaborator

If log_level not used anymore - we can delete it and make a release note that in new version it has been deleted.

@dariopnc
Copy link
Contributor Author

Removed references to log_level as suggested

@aleksandr-kotlyar
Copy link
Collaborator

@dariopnc i just discovered that all wdm logs have been disappeared. Shouldn't they be enabled by default?

@dariopnc
Copy link
Contributor Author

dariopnc commented Oct 19, 2021

@aleksandr-kotlyar Thing is logging is enabled, but it's up to the application using this module to configure a logging handler to receive log messages and handle them (add them to a file, print them in the console, send them through SOAP calls, etc)
Since automated tests seem to depend on parsing logging messages, we might need to modify the test definitions.

@dariopnc
Copy link
Contributor Author

@aleksandr-kotlyar To merge this change should I update test cases? Should I wait for someone else to do it?

@aleksandr-kotlyar
Copy link
Collaborator

aleksandr-kotlyar commented Feb 7, 2022

@dariopnc thanks for keeping your PR up to date!

I think about - how to preprare webdriver-manager users for these changes.

  1. Whats breaking changes and how to make it work again? - this info can be in PR description and in CHANGELOG.md
  2. How to fully disable logs now - this info needs to be in README.md

It will be cool if you will help to describe this info in this PR before merge and release it.

@dariopnc
Copy link
Contributor Author

dariopnc commented Feb 7, 2022

@aleksandr-kotlyar Updated doc as suggested but now I sincerely don't know why test_utils is failing
Any suggestion regarding both documentation and test is well received :)

@dariopnc
Copy link
Contributor Author

dariopnc commented Feb 7, 2022

Ok, I suppose 9f405f2 from current master is to blame for the issue... actually even current HEAD fails some tests

@aleksandr-kotlyar
Copy link
Collaborator

@aleksandr-kotlyar Updated doc as suggested but now I sincerely don't know why test_utils is failing Any suggestion regarding both documentation and test is well received :)

Thank you for your work.

I fixed test utils in new PR #298. Pull the changes please to resolve conflicts.

@dariopnc
Copy link
Contributor Author

dariopnc commented Feb 9, 2022

PR updated to current master

@dariopnc
Copy link
Contributor Author

This PR should also solve (or help solve) #277 and #287

@dariopnc dariopnc changed the title Aligned logging usage to python logging best practices Align logging usage to python logging best practices Mar 10, 2022
@dariopnc
Copy link
Contributor Author

dariopnc commented Mar 14, 2022

Hi @aleksandr-kotlyar, I've seen #343 significantly modifies the logging structure. I sincerely do not understand why this PR hasn't been considered, instead on adding a new custom behavior. Can you please explain?
The desired behavior (silent all logs) could have been achieved with this PR, by just setting WDM_LOG_LEVEL='0' as documented in the README.md file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants