浏览代码
Fix how we set logging levels (#3703)
Fix how we set logging levels (#3703)
* cleanup logging * comments and cleanup * pylint, gym/develop/add-fire
GitHub
5 年前
当前提交
4ecd6ad3
共有 24 个文件被更改,包括 108 次插入 和 59 次删除
-
2.pylintrc
-
7gym-unity/gym_unity/envs/__init__.py
-
5ml-agents-envs/mlagents_envs/environment.py
-
4ml-agents-envs/mlagents_envs/side_channel/outgoing_message.py
-
4ml-agents-envs/mlagents_envs/side_channel/side_channel.py
-
5ml-agents/mlagents/model_serialization.py
-
5ml-agents/mlagents/trainers/components/reward_signals/__init__.py
-
4ml-agents/mlagents/trainers/curriculum.py
-
5ml-agents/mlagents/trainers/env_manager.py
-
5ml-agents/mlagents/trainers/ghost/trainer.py
-
17ml-agents/mlagents/trainers/learn.py
-
4ml-agents/mlagents/trainers/meta_curriculum.py
-
4ml-agents/mlagents/trainers/policy/tf_policy.py
-
4ml-agents/mlagents/trainers/ppo/trainer.py
-
4ml-agents/mlagents/trainers/sac/optimizer.py
-
5ml-agents/mlagents/trainers/sac/trainer.py
-
7ml-agents/mlagents/trainers/stats.py
-
5ml-agents/mlagents/trainers/subprocess_env_manager.py
-
5ml-agents/mlagents/trainers/trainer/trainer.py
-
4ml-agents/mlagents/trainers/trainer_controller.py
-
5ml-agents/mlagents/trainers/trainer_util.py
-
1setup.cfg
-
46ml-agents-envs/mlagents_envs/logging_util.py
-
10ml-agents/mlagents/logging_util.py
|
|||
import logging # noqa I251 |
|||
|
|||
CRITICAL = logging.CRITICAL |
|||
FATAL = logging.FATAL |
|||
ERROR = logging.ERROR |
|||
WARNING = logging.WARNING |
|||
INFO = logging.INFO |
|||
DEBUG = logging.DEBUG |
|||
NOTSET = logging.NOTSET |
|||
|
|||
_loggers = set() |
|||
_log_level = NOTSET |
|||
DATE_FORMAT = "%Y-%m-%d %H:%M:%S" |
|||
LOG_FORMAT = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s" |
|||
|
|||
|
|||
def get_logger(name: str) -> logging.Logger: |
|||
""" |
|||
Create a logger with the specified name. The logger will use the log level |
|||
specified by set_log_level() |
|||
""" |
|||
logger = logging.getLogger(name=name) |
|||
|
|||
# If we've already set the log level, make sure new loggers use it |
|||
if _log_level != NOTSET: |
|||
logger.setLevel(_log_level) |
|||
|
|||
# Keep track of this logger so that we can change the log level later |
|||
_loggers.add(logger) |
|||
return logger |
|||
|
|||
|
|||
def set_log_level(log_level: int) -> None: |
|||
""" |
|||
Set the ML-Agents logging level. This will also configure the logging format (if it hasn't already been set). |
|||
""" |
|||
global _log_level |
|||
_log_level = log_level |
|||
|
|||
# Configure the log format. |
|||
# In theory, this would be sufficient, but if another library calls logging.basicConfig |
|||
# first, it doesn't have any effect. |
|||
logging.basicConfig(level=_log_level, format=LOG_FORMAT, datefmt=DATE_FORMAT) |
|||
|
|||
for logger in _loggers: |
|||
logger.setLevel(log_level) |
|
|||
import logging |
|||
|
|||
|
|||
def create_logger(name, log_level): |
|||
date_format = "%Y-%m-%d %H:%M:%S" |
|||
log_format = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s" |
|||
|
|||
logging.basicConfig(level=log_level, format=log_format, datefmt=date_format) |
|||
logger = logging.getLogger(name=name) |
|||
return logger |
撰写
预览
正在加载...
取消
保存
Reference in new issue