You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(If you are looking for a solution for this problem see end of this post)
🚀 Feature Request
Motivation
Is your feature request related to a problem? Please describe.
Users (me included) regularly run into the problem that logs are duplicated, e.g.: #1656#1012.
The source of this problem is that other modules (e.g. lightning) have their own logging handlers. Hydra adds its console handler to the root logger resulting in logging messages being processed twice.
A (partial) integration of the solutions provided below into the documentary to easier solve the duplicated logging message.
And / or, providing an extra job_logging yaml file option taking care of it.
Are you willing to open a pull request? (See CONTRIBUTING)
I could think of providing a .yaml file for this, however I am not yet sure about these points:
how should the file be named? Maybe non-root
How should the actual logger be named? Maybe __main__?
This would work with the already promoted getLogger(__file__), however it would need a notice to use getLogger("__main__").getChild(__file__) or similar.
Additional context
✅ Solutions for duplicated log console
The problem is that hydra adds handlers on top of modules that also implement their own handlers.
One solution is to stop the other loggers manually from propagating to the root or to remove the handlers from other modules
Do not use root handler / hydra handler
# Will use the plain format by their modulelogging.getLogger("lightning").propagate=Falselogging.getLogger("torch").propagate=False
Do not use module handlers - only the hydra logger
Likely better is to prevent the console handler to be added to root via hydra, however you need to add you own handler to the logger you are using!
hydra:
job_logging:
root:
handlers: ['file']
For example use a non-root logger named "project_logger".
Note: you need to use logging.getLogger("project_logger") or logging.getLogger("project_logger").getChild(__file__) to access it.
hydra:
job_logging:
version : 1disable_existing_loggers : Trueloggers :
project_logger :
level: 'INFO'handlers: ['console', 'file']# If propagate is True, the 'file' handler of root will be usedpropagate: Falseroot :
handlers : ['file']
The text was updated successfully, but these errors were encountered:
(If you are looking for a solution for this problem see end of this post)
🚀 Feature Request
Motivation
Is your feature request related to a problem? Please describe.
Users (me included) regularly run into the problem that logs are duplicated, e.g.: #1656 #1012.
The source of this problem is that other modules (e.g. lightning) have their own logging handlers. Hydra adds its console handler to the root logger resulting in logging messages being processed twice.
I've outlined solutions below, however it was some struggle to come up with them, a better documentation / troubleshooting guide for this problem in the documentation (https://hydra.cc/docs/configure_hydra/logging/ or https://hydra.cc/docs/tutorials/basic/running_your_app/logging/) would be helpful
Pitch
Describe the solution you'd like
A (partial) integration of the solutions provided below into the documentary to easier solve the duplicated logging message.
And / or, providing an extra job_logging yaml file option taking care of it.
Are you willing to open a pull request? (See CONTRIBUTING)
I could think of providing a .yaml file for this, however I am not yet sure about these points:
__main__
?This would work with the already promoted
getLogger(__file__)
, however it would need a notice to usegetLogger("__main__").getChild(__file__)
or similar.Additional context
✅ Solutions for duplicated log console
The problem is that hydra adds handlers on top of modules that also implement their own handlers.
One solution is to stop the other loggers manually from propagating to the root or to remove the handlers from other modules
Do not use root handler / hydra handler
Do not use module handlers - only the hydra logger
Adjust the config
Likely better is to prevent the
console
handler to be added toroot
via hydra, however you need to add you own handler to the logger you are using!For example use a non-root logger named "project_logger".
Note: you need to use
logging.getLogger("project_logger")
orlogging.getLogger("project_logger").getChild(__file__)
to access it.The text was updated successfully, but these errors were encountered: