-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix duplicate console logging bug / properly configure logging #5509
Conversation
3a7263d
to
0c581fe
Compare
Codecov Report
@@ Coverage Diff @@
## master #5509 +/- ##
======================================
- Coverage 93% 93% -0%
======================================
Files 135 135
Lines 10005 10023 +18
======================================
+ Hits 9340 9356 +16
- Misses 665 667 +2 |
43 files changed is a bit scary :D |
@Borda the change in each file is minor, just in the header of the file I replace from pytorch_lightning import _logger with import logging
_logger = logging.getLogger(__name__) I see no other way. To do the logging properly we want to respect the module hierarchy and this requires changing all occurences of logging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments, also, all these logs will not be filtered to appear just on rank zero, right?
@carmocca They weren't filtered before and they shouldn't be, since these are logs intended to be displayed on each node for investigation purposes. |
@carmocca mind re-review? |
@@ -28,6 +29,8 @@ | |||
if HOROVOD_AVAILABLE: | |||
import horovod.torch as hvd | |||
|
|||
log = logging.getLogger(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets be consistent and use the same name as you defined in __init__
:
_logger = python_logging.getLogger(__name__)
* duplicate logs * remove unused * configure basic logging * missing import * update docs for logging * import order * flake8 * test * fix test * flake8 * import warning * add changelog * isort * stderr Co-authored-by: chaton <thomas@grid.ai>
What does this PR do?
Fixes #4621
Current Behavior
The following code snippet reproduces the duplicate logs shown in the console:
Expected Behavior
We expect the following behaviors:
Scenario 1: User did not configure logging, we provide a default StreamHandler to stderr that does not propagate
Scenario 2: User configures logging, expects Lightning logs to propagate
This PR will properly configure python logging for the library. The messages get all propagated in the module hierarchy as it is recommended by python logging best practice. This gives the user the most flexibility, they can now configure logging on a module level, see the updated docs for an example.
Correct Logging Usage
In the future, if you want to use logging as part of the Lightning library, please do:
NOTE: This PR has many files changed, however the changes are small and only in the header the files. Most important changes can be found in these files:
works fine in colab too
https://colab.research.google.com/drive/1pgKFHcPkSxCRydp84PPunHQibNB-fZLq?usp=sharing