-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix how we set logging levels #3703
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
Conversation
@@ -0,0 +1,46 @@ | |||
import logging # noqa I251 |
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.
This is moved from mlagents_envs/logging_util.py
and heavily modified.
@@ -0,0 +1,46 @@ | |||
import logging # noqa I251 | |||
|
|||
CRITICAL = logging.CRITICAL |
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.
Imported here so that calling code doesn't need to import logging
gym-unity/gym_unity/envs/__init__.py
Outdated
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger("gym_unity") | ||
|
||
logger = get_logger(__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.
Recommended logging practice is to use __name__
for the logger name: https://docs.python.org/3.7/library/logging.html#logger-objects
# first, it doesn't have any effect. | ||
logging.basicConfig(level=_log_level, format=LOG_FORMAT, datefmt=DATE_FORMAT) | ||
|
||
for logger in _loggers: |
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.
In theory, if we use __name__
everywhere, we should be able to do something like
logging.getLogger("mlagents").setLevel(log_level)
logging.getLogger("mlagents_envs").setLevel(log_level)
logging.getLogger("gym_unity").setLevel(log_level)
here, and let the logger name hierarchy handle things, but I went for the explicit approach instead.
@@ -20,3 +20,4 @@ ignore = | |||
I200, | |||
|
|||
banned-modules = tensorflow = use mlagents.tf_utils instead (it handles tf2 compat). | |||
logging = use mlagents_envs.logging_util instead |
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.
This prevents logging
from being imported, so that all new code will use logging_util .get_logger
instead.
gym-unity/gym_unity/envs/__init__.py
Outdated
logger = logging.getLogger("gym_unity") | ||
|
||
logger = get_logger(__name__) | ||
set_log_level(INFO) |
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.
Very nit: it seems kind of weird to import INFO
as a global variable - could we import logging_util and do logging_util.INFO
as we do in the learn.py
?
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.
Sure, sounds good.
@@ -30,7 +29,9 @@ | |||
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfig | |||
from mlagents_envs.exception import UnityEnvironmentException | |||
from mlagents_envs.timers import hierarchical_timer, get_timer_tree | |||
from mlagents.logging_util import create_logger | |||
from mlagents_envs import logging_util |
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.
Do we need to import everything ?
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.
I received the opposite feedback from @ervteng on Friday, see #3703 (comment)
I think this is preferable when we want to use the logging levels; it's clearer in the code to see logging_util.INFO
instead of INFO
.
Another alternative is to use import logging
and disable the "banned module" error here.
@@ -30,7 +29,9 @@ | |||
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfig | |||
from mlagents_envs.exception import UnityEnvironmentException | |||
from mlagents_envs.timers import hierarchical_timer, get_timer_tree | |||
from mlagents.logging_util import create_logger | |||
from mlagents_envs import logging_util |
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.
from mlagents_envs import logging_util | |
from mlagents_envs.logging_util import get_logger, set_log_level, INFO, DEBUG |
* cleanup logging * comments and cleanup * pylint, gym
* [bug-fix] Increase height of wall in CrawlerStatic (#3650) * [bug-fix] Improve performance for PPO with continuous actions (#3662) * Corrected a typo in a name of a function (#3670) OnEpsiodeBegin was corrected to OnEpisodeBegin in Migrating.md document * Add Academy.AutomaticSteppingEnabled to migration (#3666) * Fix editor port in Dockerfile (#3674) * Hotfix memory leak on Python (#3664) * Hotfix memory leak on Python * Fixing * Fixing a bug in the heuristic policy. A decision should not be requested when the agent is done * [bug-fix] Make Python able to deal with 0-step episodes (#3671) * adding some comments Co-authored-by: Ervin T <ervin@unity3d.com> * Remove vis_encode_type from list of required (#3677) * Update changelog (#3678) * Shorten timeout duration for environment close (#3679) The timeout duration for closing an environment was set to the same duration as the timeout when waiting for a response from the still-running environment. This led to long waits for the error response when communication version wasn't matching. This change forces a timeout duration of 0 when handling errors. * Bumping the versions * handle multiple dones in a single step (#3700) * handle multiple dones in a single step * [tests] Make end-to-end tests more stable (#3697) * [bug-fix] Fix entropy computation for GaussianDistribution (#3684) * Fix how we set logging levels (#3703) * cleanup logging * comments and cleanup * pylint, gym * [skip-ci] Update changelog for logging fix. (#3707) * [skip ci] Update README * [skip ci] Fixed a typo Co-authored-by: Ervin T <ervin@unity3d.com> Co-authored-by: Adam Streck <adam.streck@gmail.com> Co-authored-by: Chris Elion <chris.elion@unity3d.com> Co-authored-by: Jonathan Harper <jharper+moar@unity3d.com>
* Bumping version on the release (#3615) * Update examples project to 2018.4.18f1 (#3618) From 2018.4.14f1. An internal package dependency was updated as a side effect. * Remove dead components from the examples scenes (#3619) (#3624) * Improve warnings and exception if using unsupported combo * add meta file * fix unit test * enforce onnx conversion (expect tf2 CI to fail) (#3600) * Update error message * Updated the release branch docs (#3621) * Updated the release branch docs * Edited the README * make sure top-level timer is closed before writing * Remove space from Product Name for examples In #2588 it was suggested that the space in the Product Name for our example environments causes confusion when using a default build because of the need to escape the space in the build filename. This change removes the space from the Product Name in the project's player settings. * [bug-fix] Increase 3dballhard and GAIL default steps (#3636) * Updating the NN models (#3632) * Updating the NN models * Update gridworld * [skip ci] Update BallHard * Update hallway * Hotfixes for Release 0.15.1 (#3698) * [bug-fix] Increase height of wall in CrawlerStatic (#3650) * [bug-fix] Improve performance for PPO with continuous actions (#3662) * Corrected a typo in a name of a function (#3670) OnEpsiodeBegin was corrected to OnEpisodeBegin in Migrating.md document * Add Academy.AutomaticSteppingEnabled to migration (#3666) * Fix editor port in Dockerfile (#3674) * Hotfix memory leak on Python (#3664) * Hotfix memory leak on Python * Fixing * Fixing a bug in the heuristic policy. A decision should not be requested when the agent is done * [bug-fix] Make Python able to deal with 0-step episodes (#3671) * adding some comments Co-authored-by: Ervin T <ervin@unity3d.com> * Remove vis_encode_type from list of required (#3677) * Update changelog (#3678) * Shorten timeout duration for environment close (#3679) The timeout duration for closing an environment was set to the same duration as the timeout when waiting for a response from the still-running environment. This led to long waits for the error response when communication version wasn't matching. This change forces a timeout duration of 0 when handling errors. * Bumping the versions * handle multiple dones in a single step (#3700) * handle multiple dones in a single step * [tests] Make end-to-end tests more stable (#3697) * [bug-fix] Fix entropy computation for GaussianDistribution (#3684) * Fix how we set logging levels (#3703) * cleanup logging * comments and cleanup * pylint, gym * [skip-ci] Update changelog for logging fix. (#3707) * [skip ci] Update README * [skip ci] Fixed a typo Co-authored-by: Ervin T <ervin@unity3d.com> Co-authored-by: Adam Streck <adam.streck@gmail.com> Co-authored-by: Chris Elion <chris.elion@unity3d.com> Co-authored-by: Jonathan Harper <jharper+moar@unity3d.com> * fix changelog * keep master gridworld Co-authored-by: Vincent-Pierre BERGES <vincentpierre@unity3d.com> Co-authored-by: Jonathan Harper <jharper+moar@unity3d.com> Co-authored-by: Ervin T <ervin@unity3d.com> Co-authored-by: Adam Streck <adam.streck@gmail.com>
Proposed change(s)
Haven't been able to reproduce this locally, but there are several reports that some log lines are not appearing. So far, the ones noted are this:
ml-agents/ml-agents-envs/mlagents_envs/environment.py
Lines 130 to 133 in 8c61299
with logged created here:
ml-agents/ml-agents-envs/mlagents_envs/environment.py
Line 50 in 8c61299
and the summary report
ml-agents/ml-agents/mlagents/trainers/trainer/trainer.py
Lines 201 to 214 in 6fa4190
configured here
ml-agents/ml-agents/mlagents/trainers/trainer/trainer.py
Line 23 in 6fa4190
The speculation is that some other import is calling
logging.basicConfig
before we get to it, so we never set the log level.This centralizes all the logging creation through logging_util (no more
logging.getLogger()
) and sets the log level explicitly for all loggers.Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
https://jira.unity3d.com/browse/MLA-737
https://jira.unity3d.com/browse/MLA-608
https://forum.unity.com/threads/prompt-doesnt-display-start-training-by-pressing-the-play-button-in-the-unity-editor.852481/
Types of change(s)
Checklist
Other comments