diff --git a/mindspore/_extends/parallel_compile/tbe_compiler/tuner.py b/mindspore/_extends/parallel_compile/tbe_compiler/tuner.py index b7fb3b72371..59afc94ffa0 100644 --- a/mindspore/_extends/parallel_compile/tbe_compiler/tuner.py +++ b/mindspore/_extends/parallel_compile/tbe_compiler/tuner.py @@ -196,8 +196,11 @@ class TbeTuner: te_log_level = os.environ.get("TE_LOGLEVEL") glog_level = os.environ.get("GLOG_v") if glog_level is not None and te_log_level is None: - os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[int(glog_level)] - global_loglevel = int(glog_level) + level = 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: os.environ["TE_LOGLEVEL"] = TE_LOG_LEVEL[2] global_loglevel = 3 diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/trt/trt_utils.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/trt/trt_utils.h index bb6aad60d38..e5be173e01b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/trt/trt_utils.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/trt/trt_utils.h @@ -117,7 +117,7 @@ class TrtLogger : public nvinfer1::ILogger { if (str_level.size() == 1) { int ch = str_level.c_str()[0]; 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(ch); } } diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/ascend_kernel_compile.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/ascend_kernel_compile.cc index f93f5176692..b85f567f7c2 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/ascend_kernel_compile.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/ascend_kernel_compile.cc @@ -191,6 +191,8 @@ int StrToInt(const std::string &env) { return INFO; } else if (env == "3") { return ERROR; + } else if (env == "4") { + return EXCEPTION; } return WARNING; } diff --git a/mindspore/context.py b/mindspore/context.py index bd44f719a0a..37d680f4f77 100644 --- a/mindspore/context.py +++ b/mindspore/context.py @@ -62,7 +62,7 @@ def _make_directory(path): os.makedirs(path) real_path = path 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}`.") return real_path diff --git a/mindspore/dataset/engine/datasets.py b/mindspore/dataset/engine/datasets.py index ae70b076ed0..d5a80e0030e 100644 --- a/mindspore/dataset/engine/datasets.py +++ b/mindspore/dataset/engine/datasets.py @@ -2456,8 +2456,8 @@ def _watch_dog(eot, pids): wait_pid() ## multiprocessing.queue may hang in .get() forever when put() process was killed. ## We have to exit main process otherwise main process will hang. - logger.error("The subprocess of dataset may exit unexpected or be killed, " - "main process will exit.") + logger.exception("The subprocess of dataset may exit unexpected or be killed, " + "main process will exit.") os.kill(os.getpid(), signal.SIGTERM) @@ -2608,7 +2608,7 @@ class _ExceptHookHandler: sys.excepthook = self.__handler_exception 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() diff --git a/mindspore/dataset/engine/iterators.py b/mindspore/dataset/engine/iterators.py index 956680e6128..6dcc3ff719c 100644 --- a/mindspore/dataset/engine/iterators.py +++ b/mindspore/dataset/engine/iterators.py @@ -180,7 +180,7 @@ class DictIterator(Iterator): ## maybe "Out of memory" / "MemoryError" error err_info = str(err) 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) raise err diff --git a/mindspore/log.py b/mindspore/log.py index 118a9b04f23..af22c4e93ee 100644 --- a/mindspore/log.py +++ b/mindspore/log.py @@ -53,6 +53,7 @@ _name_to_level = { 'INFO': 20, 'WARNING': 30, 'ERROR': 40, + 'EXCEPTION': 50, } # GLog level and level name @@ -61,7 +62,7 @@ _gloglevel_to_name = { '1': 'INFO', '2': 'WARNING', '3': 'ERROR', - '4': 'ERROR', + '4': 'EXCEPTION', } # The mapping of logger configurations to glog configurations @@ -211,16 +212,16 @@ def 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): """Log a message with severity 'WARNING' on the MindSpore logger.""" _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(): """ Get the logger level. @@ -503,6 +504,8 @@ def _setup_logger(kwargs): if _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}') # Override findCaller on the logger, Support for getting log record logger.findCaller = _find_caller diff --git a/tests/ut/python/test_log.py b/tests/ut/python/test_log.py index 9d767caf9a2..ef78b5be6e6 100644 --- a/tests/ut/python/test_log.py +++ b/tests/ut/python/test_log.py @@ -33,6 +33,7 @@ def test_log_stdout(): logger.info("2 test log message info :%s", log_str) logger.warning("3 test log message warning :%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 _clear_logger(logger)