浏览代码

use logging instead of print

Replaced the print statements with logging statements in the exception.py file
Uses the same logger as the environment one
named the logger unityagents
/tag-0.2.0
vincentpierre 7 年前
当前提交
50f91f66
共有 2 个文件被更改,包括 20 次插入15 次删除
  1. 2
      python/unityagents/environment.py
  2. 33
      python/unityagents/exception.py

2
python/unityagents/environment.py


from sys import platform
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger = logging.getLogger("unityagents")
class UnityEnvironment(object):

33
python/unityagents/exception.py


import logging
logger = logging.getLogger("unityagents")
class UnityEnvironmentException(Exception):
"""
Related to errors starting and closing environment.

def __init__(self, message, log_file_path = None):
if log_file_path is not None:
try:
with open(log_file_path, "r") as f:
printing = False
for l in f:
l=l.strip()
if (l == 'Exception') or (l=='Error'):
printing = True
print('----------------------')
if (l == ''):
printing = False
if printing:
print(l)
print("An error might have occured in the environment. "
"You can check the logfile for more information at {}".format(log_file_path))
with open(log_file_path, "r") as f:
printing = False
unity_error = '\n'
for l in f:
l=l.strip()
if (l == 'Exception') or (l=='Error'):
printing = True
unity_error += '----------------------\n'
if (l == ''):
printing = False
if printing:
unity_error += l + '\n'
logger.info(unity_error)
logger.error("An error might have occured in the environment. "
"You can check the logfile for more information at {}".format(log_file_path))
print("An error might have occured in the environment. "
logger.error("An error might have occured in the environment. "
"No unity-environment.log file could be found.")
super(UnityTimeOutException, self).__init__(message)
正在加载...
取消
保存