forked from mindspore-Ecosystem/mindspore
add exception level to python error report
This commit is contained in:
parent
3b065f5413
commit
3ee5d98a8d
|
@ -196,8 +196,11 @@ class TbeTuner:
|
||||||
te_log_level = os.environ.get("TE_LOGLEVEL")
|
te_log_level = os.environ.get("TE_LOGLEVEL")
|
||||||
glog_level = os.environ.get("GLOG_v")
|
glog_level = os.environ.get("GLOG_v")
|
||||||
if glog_level is not None and te_log_level is None:
|
if glog_level is not None and te_log_level is None:
|
||||||
os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[int(glog_level)]
|
level = int(glog_level)
|
||||||
global_loglevel = int(glog_level)
|
if level >= len(TE_LOG_LEVEL):
|
||||||
|
level = len(TE_LOG_LEVEL) - 1
|
||||||
|
os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[level]
|
||||||
|
global_loglevel = level
|
||||||
elif glog_level is None and te_log_level is None:
|
elif glog_level is None and te_log_level is None:
|
||||||
os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[2]
|
os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[2]
|
||||||
global_loglevel = 3
|
global_loglevel = 3
|
||||||
|
|
|
@ -117,7 +117,7 @@ class TrtLogger : public nvinfer1::ILogger {
|
||||||
if (str_level.size() == 1) {
|
if (str_level.size() == 1) {
|
||||||
int ch = str_level.c_str()[0];
|
int ch = str_level.c_str()[0];
|
||||||
ch = ch - '0'; // subtract ASCII code of '0', which is 48
|
ch = ch - '0'; // subtract ASCII code of '0', which is 48
|
||||||
if (ch >= mindspore::DEBUG && ch <= mindspore::ERROR) {
|
if (ch >= mindspore::DEBUG && ch <= mindspore::EXCEPTION) {
|
||||||
log_level_ = static_cast<MsLogLevel>(ch);
|
log_level_ = static_cast<MsLogLevel>(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,8 @@ int StrToInt(const std::string &env) {
|
||||||
return INFO;
|
return INFO;
|
||||||
} else if (env == "3") {
|
} else if (env == "3") {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
} else if (env == "4") {
|
||||||
|
return EXCEPTION;
|
||||||
}
|
}
|
||||||
return WARNING;
|
return WARNING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ def _make_directory(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
real_path = path
|
real_path = path
|
||||||
except PermissionError as e:
|
except PermissionError as e:
|
||||||
logger.error(f"No write permission on the directory `{path}, error = {e}")
|
logger.error(f"No write permission on the directory `{path}`, error = {e}")
|
||||||
raise ValueError(f"No write permission on the directory `{path}`.")
|
raise ValueError(f"No write permission on the directory `{path}`.")
|
||||||
return real_path
|
return real_path
|
||||||
|
|
||||||
|
|
|
@ -2456,7 +2456,7 @@ def _watch_dog(eot, pids):
|
||||||
wait_pid()
|
wait_pid()
|
||||||
## multiprocessing.queue may hang in .get() forever when put() process was killed.
|
## multiprocessing.queue may hang in .get() forever when put() process was killed.
|
||||||
## We have to exit main process otherwise main process will hang.
|
## We have to exit main process otherwise main process will hang.
|
||||||
logger.error("The subprocess of dataset may exit unexpected or be killed, "
|
logger.exception("The subprocess of dataset may exit unexpected or be killed, "
|
||||||
"main process will exit.")
|
"main process will exit.")
|
||||||
os.kill(os.getpid(), signal.SIGTERM)
|
os.kill(os.getpid(), signal.SIGTERM)
|
||||||
|
|
||||||
|
@ -2608,7 +2608,7 @@ class _ExceptHookHandler:
|
||||||
sys.excepthook = self.__handler_exception
|
sys.excepthook = self.__handler_exception
|
||||||
|
|
||||||
def __handler_exception(self, ex_type, value, tb):
|
def __handler_exception(self, ex_type, value, tb):
|
||||||
logger.error("Uncaught exception: ", exc_info=(ex_type, value, tb))
|
logger.exception("Uncaught exception: ", exc_info=(ex_type, value, tb))
|
||||||
_mp_pool_exit_preprocess()
|
_mp_pool_exit_preprocess()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ class DictIterator(Iterator):
|
||||||
## maybe "Out of memory" / "MemoryError" error
|
## maybe "Out of memory" / "MemoryError" error
|
||||||
err_info = str(err)
|
err_info = str(err)
|
||||||
if err_info.find("Out of memory") >= 0 or err_info.find("MemoryError") >= 0:
|
if err_info.find("Out of memory") >= 0 or err_info.find("MemoryError") >= 0:
|
||||||
logger.error("Memory error occurred, process will exit.")
|
logger.exception("Memory error occurred, process will exit.")
|
||||||
os.kill(os.getpid(), signal.SIGKILL)
|
os.kill(os.getpid(), signal.SIGKILL)
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ _name_to_level = {
|
||||||
'INFO': 20,
|
'INFO': 20,
|
||||||
'WARNING': 30,
|
'WARNING': 30,
|
||||||
'ERROR': 40,
|
'ERROR': 40,
|
||||||
|
'EXCEPTION': 50,
|
||||||
}
|
}
|
||||||
|
|
||||||
# GLog level and level name
|
# GLog level and level name
|
||||||
|
@ -61,7 +62,7 @@ _gloglevel_to_name = {
|
||||||
'1': 'INFO',
|
'1': 'INFO',
|
||||||
'2': 'WARNING',
|
'2': 'WARNING',
|
||||||
'3': 'ERROR',
|
'3': 'ERROR',
|
||||||
'4': 'ERROR',
|
'4': 'EXCEPTION',
|
||||||
}
|
}
|
||||||
|
|
||||||
# The mapping of logger configurations to glog configurations
|
# The mapping of logger configurations to glog configurations
|
||||||
|
@ -211,16 +212,16 @@ def error(msg, *args, **kwargs):
|
||||||
_get_logger().error(msg, *args, **kwargs)
|
_get_logger().error(msg, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def exception(msg, *args, **kwargs):
|
|
||||||
"""Log a message with severity 'EXCEPTION' on the MindSpore logger."""
|
|
||||||
_get_logger().exception(msg, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def warning(msg, *args, **kwargs):
|
def warning(msg, *args, **kwargs):
|
||||||
"""Log a message with severity 'WARNING' on the MindSpore logger."""
|
"""Log a message with severity 'WARNING' on the MindSpore logger."""
|
||||||
_get_logger().warning(msg, *args, **kwargs)
|
_get_logger().warning(msg, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def exception(msg, *args, **kwargs):
|
||||||
|
"""Use logging.critical to log a message with severity 'EXCEPTION' on the MindSpore logger."""
|
||||||
|
_get_logger().critical(msg, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_level():
|
def get_level():
|
||||||
"""
|
"""
|
||||||
Get the logger level.
|
Get the logger level.
|
||||||
|
@ -503,6 +504,8 @@ def _setup_logger(kwargs):
|
||||||
if _global_logger:
|
if _global_logger:
|
||||||
return _global_logger
|
return _global_logger
|
||||||
|
|
||||||
|
# Set the level name of logging.CRITICAL to EXCEPTION
|
||||||
|
logging.addLevelName(logging.CRITICAL, 'EXCEPTION')
|
||||||
logger = logging.getLogger(name=f'{sub_module}.{log_name}')
|
logger = logging.getLogger(name=f'{sub_module}.{log_name}')
|
||||||
# Override findCaller on the logger, Support for getting log record
|
# Override findCaller on the logger, Support for getting log record
|
||||||
logger.findCaller = _find_caller
|
logger.findCaller = _find_caller
|
||||||
|
|
|
@ -33,6 +33,7 @@ def test_log_stdout():
|
||||||
logger.info("2 test log message info :%s", log_str)
|
logger.info("2 test log message info :%s", log_str)
|
||||||
logger.warning("3 test log message warning :%s", log_str)
|
logger.warning("3 test log message warning :%s", log_str)
|
||||||
logger.debug("4 test log message debug:%s", log_str)
|
logger.debug("4 test log message debug:%s", log_str)
|
||||||
|
logger.exception("5 test log message exception :{}".format(log_str))
|
||||||
# Clean up _global_logger to avoid affecting for next usecase
|
# Clean up _global_logger to avoid affecting for next usecase
|
||||||
_clear_logger(logger)
|
_clear_logger(logger)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue