From 86efc91cb253c5509b09f238316f659779faa80e Mon Sep 17 00:00:00 2001 From: taipingchangan <1196608768@qq.com> Date: Thu, 25 Aug 2022 09:48:43 +0800 Subject: [PATCH] adapt log to windows --- .../backend/common/session/kernel_graph.cc | 2 +- mindspore/ccsrc/debug/debug_services.cc | 4 +- .../ccsrc/frontend/optimizer/optimizer.h | 2 +- .../ccsrc/include/common/utils/contract.h | 2 +- .../dataset/engine/cache/cache_admin_arg.cc | 2 +- .../engine/opt/pre/node_offload_pass.cc | 2 +- .../minddata/dataset/plugin/plugin_loader.cc | 2 +- mindspore/ccsrc/pipeline/jit/parse/parse.cc | 4 +- .../jit/static_analysis/async_eval_result.cc | 2 +- .../jit/static_analysis/async_eval_result.h | 4 +- .../pipeline/pynative/pynative_execute.cc | 4 ++ .../ascend/kernel/tbe/tbe_kernel_compile.cc | 13 ++--- .../plugin/device/gpu/kernel/trt/trt_utils.h | 14 ++--- .../ccsrc/ps/core/communicator/tcp_client.cc | 16 +++--- .../ccsrc/ps/core/communicator/tcp_server.cc | 8 +-- mindspore/core/CMakeLists.txt | 4 +- mindspore/core/abstract/abstract_value.cc | 2 +- mindspore/core/mindapi/base/logging.h | 12 ++--- mindspore/core/mindapi/src/logging.cc | 22 ++++---- mindspore/core/utils/log_adapter.cc | 52 +++++++++---------- mindspore/core/utils/log_adapter.h | 25 +++++---- 21 files changed, 104 insertions(+), 94 deletions(-) diff --git a/mindspore/ccsrc/backend/common/session/kernel_graph.cc b/mindspore/ccsrc/backend/common/session/kernel_graph.cc index 07bb3879c08..37a5a5e8277 100644 --- a/mindspore/ccsrc/backend/common/session/kernel_graph.cc +++ b/mindspore/ccsrc/backend/common/session/kernel_graph.cc @@ -1053,7 +1053,7 @@ std::vector KernelGraph::FindNodeByPrimitive(const std::vector *const name, std:: if (tensor_list_size == 0) { return; } - if (IS_OUTPUT_ON(INFO)) { + if (IS_OUTPUT_ON(mindspore::kInfo)) { wp_progress_enabled_ = true; wp_progress_thread_ = std::make_unique([this, tensor_list_size]() { CheckWatchpointProgress(tensor_list_size); }); @@ -668,7 +668,7 @@ void DebugServices::CheckWatchpoints(std::vector *const name, std:: MS_LOG(INFO) << "tensor_list byte size is " << tensor_list_byte_size / pow(10.0, 6.0) << " MB"; MS_LOG(INFO) << "CheckWatchpoints Took: " << std::fixed << std::setprecision(precision) << (ms_double.count()) / ms_to_s << "s"; - if (IS_OUTPUT_ON(INFO) && wp_progress_thread_ && wp_progress_thread_->joinable()) { + if (IS_OUTPUT_ON(mindspore::kInfo) && wp_progress_thread_ && wp_progress_thread_->joinable()) { wp_progress_enabled_ = false; wp_progress_thread_->join(); MS_LOG(INFO) << "Join wp_progress_thread_."; diff --git a/mindspore/ccsrc/frontend/optimizer/optimizer.h b/mindspore/ccsrc/frontend/optimizer/optimizer.h index 8f3614420e9..ad4f7bd8f22 100644 --- a/mindspore/ccsrc/frontend/optimizer/optimizer.h +++ b/mindspore/ccsrc/frontend/optimizer/optimizer.h @@ -106,7 +106,7 @@ class Optimizer : public std::enable_shared_from_this { run_only_once_ = run_only_once; is_watch_renormalize_ = false; is_untyped_generated_ = false; - is_on_debug_ = IS_OUTPUT_ON(mindspore::DEBUG); + is_on_debug_ = IS_OUTPUT_ON(mindspore::kDebug); for (auto &iter : passes) { const std::string &name = iter.first; diff --git a/mindspore/ccsrc/include/common/utils/contract.h b/mindspore/ccsrc/include/common/utils/contract.h index a44a04e0917..1a513711244 100644 --- a/mindspore/ccsrc/include/common/utils/contract.h +++ b/mindspore/ccsrc/include/common/utils/contract.h @@ -56,7 +56,7 @@ class Ensures : public EnsuresAccess { if (!R::Check(value_)) { LogStream contract_stream; contract_stream << "contract error: " << signatory.extra_info << R::Desc(); - LogWriter(signatory.location_info, EXCEPTION, SUBMODULE_ID, ArgumentError) ^ contract_stream; + LogWriter(signatory.location_info, MsLogLevel::kException, SUBMODULE_ID, ArgumentError) ^ contract_stream; } } template >> diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin_arg.cc b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin_arg.cc index ab2a4f19e78..6b015b73b97 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin_arg.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin_arg.cc @@ -380,7 +380,7 @@ Status CacheAdminArgHandler::Validate() { "Number of workers must be in range of 1 and " + std::to_string(max_num_workers) + "."); } - if (log_level_ < MsLogLevel::DEBUG || log_level_ > MsLogLevel::EXCEPTION) { + if (log_level_ < MsLogLevel::kDebug || log_level_ > MsLogLevel::kException) { return Status(StatusCode::kMDSyntaxError, "Log level must be in range (0..4)."); } diff --git a/mindspore/ccsrc/minddata/dataset/engine/opt/pre/node_offload_pass.cc b/mindspore/ccsrc/minddata/dataset/engine/opt/pre/node_offload_pass.cc index 27f6885663c..cde7c698d57 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/opt/pre/node_offload_pass.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/opt/pre/node_offload_pass.cc @@ -37,7 +37,7 @@ Status NodeOffloadPass::OffloadNodes::Visit(std::shared_ptr node, bool if ((manual_offload == ManualOffloadMode::kEnabled) || ((auto_offload_ == true) && (manual_offload != ManualOffloadMode::kDisabled))) { bool offload_supported = true; - if (IS_OUTPUT_ON(mindspore::INFO)) { + if (IS_OUTPUT_ON(mindspore::kInfo)) { std::string operations = "operations=["; auto op_list = node->operations(); std::for_each(op_list.begin(), op_list.end(), [&](const auto &op) { diff --git a/mindspore/ccsrc/minddata/dataset/plugin/plugin_loader.cc b/mindspore/ccsrc/minddata/dataset/plugin/plugin_loader.cc index 52b8026c4b7..9aef758b464 100644 --- a/mindspore/ccsrc/minddata/dataset/plugin/plugin_loader.cc +++ b/mindspore/ccsrc/minddata/dataset/plugin/plugin_loader.cc @@ -36,7 +36,7 @@ PluginLoader::~PluginLoader() { std::transform(plugins_.begin(), plugins_.end(), std::back_inserter(keys), [](const auto &p) { return p.first; }); for (std::string &key : keys) { Status rc = UnloadPlugin(key); - MSLOG_IF(ERROR, rc.IsError(), mindspore::NoExceptionType) << rc.ToString(); + MSLOG_IF(MsLogLevel::kError, rc.IsError(), mindspore::NoExceptionType) << rc.ToString(); } } diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index 9ff5381096f..7959775d477 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -3017,7 +3017,7 @@ FunctionBlockPtr Parser::ParseWith(const FunctionBlockPtr &block, const py::obje void Parser::PrintPhiArgMaps(const std::map> &phi_to_args, const std::map> &arg_to_phis) { - if (!IS_OUTPUT_ON(DEBUG)) { + if (!IS_OUTPUT_ON(mindspore::kDebug)) { return; } std::ostringstream oss; @@ -3135,7 +3135,7 @@ std::shared_ptr> Parser::CollectRemovablePhiA (*need_remove_phi_args)[phi] = *(args.begin()); } } - if (IS_OUTPUT_ON(DEBUG)) { + if (IS_OUTPUT_ON(mindspore::kDebug)) { size_t m = 0; std::ostringstream oss; oss << "=====================Need removed phis and args=====================" diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.cc index a0f2373e4f0..4043baa0b34 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.cc @@ -38,7 +38,7 @@ void AnalysisSchedule::Schedule() { MS_LOG(DEBUG) << "Success to exit."; } -void AnalysisSchedule::Yield(AsyncInferTask *async_infer_task) { +void AnalysisSchedule::YieldTask(AsyncInferTask *async_infer_task) { MS_EXCEPTION_IF_NULL(async_infer_task); { std::lock_guard activeLock(activate_thread_lock_); diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h index 73118f1e7d4..d711f868168 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h @@ -57,7 +57,7 @@ class AnalysisSchedule { void Wait(); void Add2Schedule(const AsyncInferTaskPtr &async_infer_task_ptr); void WaitForRun() const; - void Yield(AsyncInferTask *asyncTask); + void YieldTask(AsyncInferTask *asyncTask); void EnterWaiting() { { @@ -327,7 +327,7 @@ class AsyncInferTask { AbstractBasePtr GetResult() { StaticAnalysisException::Instance().CheckException(); - AnalysisSchedule::GetInstance().Yield(this); + AnalysisSchedule::GetInstance().YieldTask(this); std::unique_lock lock(lock_); MS_LOG(DEBUG) << AnalysisSchedule::thread_id() << " waiting."; condition_var_.wait(lock, [this] { return ready_; }); diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index 6662a86d568..909e1760974 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -70,10 +70,14 @@ void PyNativeExecutorTry(const std::function &met throw(std::runtime_error(ex.what())); } catch (...) { inst->ClearRes(); +#ifndef _MSC_VER auto exception_type = abi::__cxa_current_exception_type(); MS_EXCEPTION_IF_NULL(exception_type); std::string ex_name(exception_type->name()); MS_LOG(EXCEPTION) << "Error occurred when compile graph. Exception name: " << ex_name; +#else + MS_LOG(EXCEPTION) << "Error occurred when compile graph."; +#endif } } } // namespace diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_kernel_compile.cc b/mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_kernel_compile.cc index d23b8fa8ad8..90e80c817ff 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_kernel_compile.cc +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_kernel_compile.cc @@ -138,13 +138,13 @@ void PrintInfo(const nlohmann::json &info, const std::string &job_name, const in auto message = GetJsonValue(info, kMessage); if (level == 0) { MS_LOG(DEBUG) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; - } else if (level == static_cast(INFO)) { + } else if (level == static_cast(MsLogLevel::kInfo)) { MS_LOG(INFO) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; - } else if (level == static_cast(WARNING)) { + } else if (level == static_cast(MsLogLevel::kWarning)) { MS_LOG(WARNING) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; - } else if (level == static_cast(ERROR)) { + } else if (level == static_cast(MsLogLevel::kError)) { MS_LOG(ERROR) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; - } else if (level == static_cast(EXCEPTION)) { + } else if (level == static_cast(MsLogLevel::kException)) { ReportToErrorManager(message); } } @@ -238,7 +238,8 @@ std::vector GetTuneOpsList(const std::string &d) { } } // namespace -void TbeKernelCompileManager::PrintProcessLog(const nlohmann::json &json, int adjust_log_level = EXCEPTION) const { +void TbeKernelCompileManager::PrintProcessLog(const nlohmann::json &json, + int adjust_log_level = MsLogLevel::kException) const { auto all_logs = GetJsonValue>(json, kProcessInfo); auto job_id = GetJsonValue(json, kJobId); auto json_name = GetJsonValue(json, kFusionOpName); @@ -590,7 +591,7 @@ std::string TbeKernelCompileManager::ParseSelectAndCheckResult(const nlohmann::j return kFailed; } if (res != kFullySupported) { - PrintProcessLog(json, static_cast(DEBUG)); + PrintProcessLog(json, static_cast(MsLogLevel::kDebug)); } } else if (json.at(kStatus) == kFailed) { auto all_logs = GetJsonValue>(json, kProcessInfo); diff --git a/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h b/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h index e05ac856541..24689c6bd0d 100644 --- a/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h +++ b/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h @@ -107,7 +107,7 @@ class TrtUtils { class TrtLogger : public nvinfer1::ILogger { public: TrtLogger() { - log_level_ = MsLogLevel::WARNING; // set default log level to WARNING + log_level_ = MsLogLevel::kWarning; // set default log level to WARNING const char *glog_config = std::getenv("GLOG_v"); if (glog_config == nullptr) { return; @@ -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::EXCEPTION) { + if (ch >= MsLogLevel::kDebug && ch <= MsLogLevel::kException) { log_level_ = static_cast(ch); } } @@ -127,11 +127,11 @@ class TrtLogger : public nvinfer1::ILogger { #ifdef USE_GLOG #define google mindspore_private static std::map> logger_map = { - {Severity::kVERBOSE, {MsLogLevel::DEBUG, google::GLOG_INFO, "VERBOSE"}}, - {Severity::kINFO, {MsLogLevel::INFO, google::GLOG_INFO, "INFO"}}, - {Severity::kWARNING, {MsLogLevel::WARNING, google::GLOG_WARNING, "WARNING"}}, - {Severity::kERROR, {MsLogLevel::ERROR, google::GLOG_ERROR, "ERROR"}}, - {Severity::kINTERNAL_ERROR, {MsLogLevel::ERROR, google::GLOG_ERROR, "INTERNAL ERROR"}}}; + {Severity::kVERBOSE, {MsLogLevel::kDebug, google::GLOG_INFO, "VERBOSE"}}, + {Severity::kINFO, {MsLogLevel::kInfo, google::GLOG_INFO, "INFO"}}, + {Severity::kWARNING, {MsLogLevel::kWarning, google::GLOG_WARNING, "WARNING"}}, + {Severity::kERROR, {MsLogLevel::kError, google::GLOG_ERROR, "ERROR"}}, + {Severity::kINTERNAL_ERROR, {MsLogLevel::kError, google::GLOG_ERROR, "INTERNAL ERROR"}}}; auto iter = logger_map.find(severity); if (iter == logger_map.end()) { diff --git a/mindspore/ccsrc/ps/core/communicator/tcp_client.cc b/mindspore/ccsrc/ps/core/communicator/tcp_client.cc index 3c07aff193e..fa8367e5c78 100644 --- a/mindspore/ccsrc/ps/core/communicator/tcp_client.cc +++ b/mindspore/ccsrc/ps/core/communicator/tcp_client.cc @@ -315,11 +315,11 @@ void TcpClient::Start() { int ret = event_base_dispatch(event_base_); // is_started_ should be false when finish dispatch is_started_ = false; - MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base dispatch success!"; - MSLOG_IF(mindspore::ERROR, ret == 1, NoExceptionType) + MSLOG_IF(MsLogLevel::kInfo, ret == 0, NoExceptionType) << "Event base dispatch success!"; + MSLOG_IF(MsLogLevel::kError, ret == 1, NoExceptionType) << "Event base dispatch failed with no events pending or active!"; - MSLOG_IF(mindspore::ERROR, ret == -1, NoExceptionType) << "Event base dispatch failed with error occurred!"; - MSLOG_IF(mindspore::EXCEPTION, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!"; + MSLOG_IF(MsLogLevel::kError, ret == -1, NoExceptionType) << "Event base dispatch failed with error occurred!"; + MSLOG_IF(MsLogLevel::kException, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!"; } void TcpClient::StartWithNoBlock() { @@ -327,10 +327,10 @@ void TcpClient::StartWithNoBlock() { MS_LOG(INFO) << "Start tcp client with no block!"; MS_EXCEPTION_IF_NULL(event_base_); int ret = event_base_loop(event_base_, EVLOOP_NONBLOCK); - MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base loop success!"; - MSLOG_IF(mindspore::ERROR, ret == 1, NoExceptionType) << "Event base loop failed with no events pending or active!"; - MSLOG_IF(mindspore::ERROR, ret == -1, NoExceptionType) << "Event base loop failed with error occurred!"; - MSLOG_IF(mindspore::EXCEPTION, ret < -1, AbortedError) << "Event base loop with unexpected error code!"; + MSLOG_IF(MsLogLevel::kInfo, ret == 0, NoExceptionType) << "Event base loop success!"; + MSLOG_IF(MsLogLevel::kError, ret == 1, NoExceptionType) << "Event base loop failed with no events pending or active!"; + MSLOG_IF(MsLogLevel::kError, ret == -1, NoExceptionType) << "Event base loop failed with error occurred!"; + MSLOG_IF(MsLogLevel::kException, ret < -1, AbortedError) << "Event base loop with unexpected error code!"; } void TcpClient::SetMessageCallback(const OnMessage &cb) { message_callback_ = cb; } diff --git a/mindspore/ccsrc/ps/core/communicator/tcp_server.cc b/mindspore/ccsrc/ps/core/communicator/tcp_server.cc index 664860ae8c3..07a8da92348 100644 --- a/mindspore/ccsrc/ps/core/communicator/tcp_server.cc +++ b/mindspore/ccsrc/ps/core/communicator/tcp_server.cc @@ -205,11 +205,11 @@ void TcpServer::Start() { MS_LOG(INFO) << "Start tcp server!"; MS_EXCEPTION_IF_NULL(base_); int ret = event_base_dispatch(base_); - MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base dispatch success!"; - MSLOG_IF(mindspore::ERROR, ret == 1, NoExceptionType) + MSLOG_IF(MsLogLevel::kInfo, ret == 0, NoExceptionType) << "Event base dispatch success!"; + MSLOG_IF(MsLogLevel::kError, ret == 1, NoExceptionType) << "Event base dispatch failed with no events pending or active!"; - MSLOG_IF(mindspore::ERROR, ret == -1, NoExceptionType) << "Event base dispatch failed with error occurred!"; - MSLOG_IF(mindspore::EXCEPTION, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!"; + MSLOG_IF(MsLogLevel::kError, ret == -1, NoExceptionType) << "Event base dispatch failed with error occurred!"; + MSLOG_IF(MsLogLevel::kException, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!"; } void TcpServer::Stop() { diff --git a/mindspore/core/CMakeLists.txt b/mindspore/core/CMakeLists.txt index cd5254a1dca..439f00e1ef3 100644 --- a/mindspore/core/CMakeLists.txt +++ b/mindspore/core/CMakeLists.txt @@ -58,8 +58,10 @@ else() ms_protobuf_generate(PROTO_SRCS PROTO_HDRS ${PROTO_FILE}) endif() -if(CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT MSVC) +if(CMAKE_SYSTEM_NAME MATCHES "Windows") + if(NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -DHAVE_SNPRINTF") + endif() add_compile_definitions(BUILDING_DLL) elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ diff --git a/mindspore/core/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc index 2b4cfd8dd1c..df9db44e728 100644 --- a/mindspore/core/abstract/abstract_value.cc +++ b/mindspore/core/abstract/abstract_value.cc @@ -331,7 +331,7 @@ void SynchronizeSequenceNodesElementsUseFlagsInner(const AnfNodeWeakPtrList &seq } void CheckSequenceNodesValid(const AnfNodeWeakPtrList &sequence_nodes) { - if (!IS_OUTPUT_ON(DEBUG)) { + if (!IS_OUTPUT_ON(MsLogLevel::kDebug)) { return; } if (sequence_nodes.size() <= 1) { diff --git a/mindspore/core/mindapi/base/logging.h b/mindspore/core/mindapi/base/logging.h index d918a22e383..453cc363685 100644 --- a/mindspore/core/mindapi/base/logging.h +++ b/mindspore/core/mindapi/base/logging.h @@ -25,7 +25,7 @@ #include "utils/macros.h" namespace mindspore::api { -enum class LogLevel : uint8_t { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION }; +enum class LogLevel : uint8_t { kDebug = 0, kInfo, kWarning, kError, kException }; class LogWriterImpl; @@ -90,11 +90,11 @@ class MIND_API LogWriter { #define MIND_LOG_IF(L) \ if (MIND_LOG_WRITER::IsEnabled(MIND_LOG_LEVEL(L))) MIND_LOG_WRITE(L) -#define MIND_LOG_DEBUG MIND_LOG_IF(DEBUG) -#define MIND_LOG_INFO MIND_LOG_IF(INFO) -#define MIND_LOG_WARNING MIND_LOG_IF(WARNING) -#define MIND_LOG_ERROR MIND_LOG_IF(ERROR) -#define MIND_LOG_EXCEPTION MIND_LOG_THROW(EXCEPTION) +#define MIND_LOG_DEBUG MIND_LOG_IF(kDebug) +#define MIND_LOG_INFO MIND_LOG_IF(kInfo) +#define MIND_LOG_WARNING MIND_LOG_IF(kWarning) +#define MIND_LOG_ERROR MIND_LOG_IF(kError) +#define MIND_LOG_EXCEPTION MIND_LOG_THROW(kException) #define MIND_LOG(level) MIND_LOG_##level #if !defined(MIND_LOG_NO_MS_LOG) && !defined(MS_LOG) diff --git a/mindspore/core/mindapi/src/logging.cc b/mindspore/core/mindapi/src/logging.cc index 06b816ec05f..8a0fff11813 100644 --- a/mindspore/core/mindapi/src/logging.cc +++ b/mindspore/core/mindapi/src/logging.cc @@ -22,18 +22,18 @@ namespace mindspore::api { static MsLogLevel ToMsLogLevel(LogLevel level) { switch (level) { - case LogLevel::DEBUG: - return MsLogLevel::DEBUG; - case LogLevel::INFO: - return MsLogLevel::INFO; - case LogLevel::WARNING: - return MsLogLevel::WARNING; - case LogLevel::ERROR: - return MsLogLevel::ERROR; - case LogLevel::EXCEPTION: - return MsLogLevel::EXCEPTION; + case LogLevel::kDebug: + return MsLogLevel::kDebug; + case LogLevel::kInfo: + return MsLogLevel::kInfo; + case LogLevel::kWarning: + return MsLogLevel::kWarning; + case LogLevel::kError: + return MsLogLevel::kError; + case LogLevel::kException: + return MsLogLevel::kException; default: - return MsLogLevel::EXCEPTION; + return MsLogLevel::kException; } } diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc index 6a866a02774..7f55fc09294 100644 --- a/mindspore/core/utils/log_adapter.cc +++ b/mindspore/core/utils/log_adapter.cc @@ -40,11 +40,11 @@ constexpr auto kSplitLine = "\n------------------------------------------------- constexpr const char *ANDROID_LOG_TAG = "MS_LITE"; #endif // set default log level to WARNING for all sub modules -int g_ms_submodule_log_levels[NUM_SUBMODUES] = {WARNING}; +int g_ms_submodule_log_levels[NUM_SUBMODUES] = {MsLogLevel::kWarning}; #if defined(_WIN32) || defined(_WIN64) -enum MsLogLevel this_thread_max_log_level = EXCEPTION; +enum MsLogLevel this_thread_max_log_level = MsLogLevel::kException; #else -thread_local enum MsLogLevel this_thread_max_log_level = EXCEPTION; +thread_local enum MsLogLevel this_thread_max_log_level = MsLogLevel::kException; #endif #ifdef USE_GLOG @@ -82,13 +82,13 @@ static std::string GetLogLevel(MsLogLevel level) { // convert MsLogLevel to corresponding glog level static int GetGlogLevel(MsLogLevel level) { switch (level >= this_thread_max_log_level ? this_thread_max_log_level : level) { - case DEBUG: - case INFO: + case MsLogLevel::kDebug: + case MsLogLevel::kInfo: return google::GLOG_INFO; - case WARNING: + case MsLogLevel::kWarning: return google::GLOG_WARNING; - case ERROR: - case EXCEPTION: + case MsLogLevel::kError: + case MsLogLevel::kException: default: return google::GLOG_ERROR; } @@ -111,13 +111,13 @@ static int GetThresholdLevel(const std::string &threshold) { #undef google #elif defined(BUILD_CORE_RUNTIME) const char *EnumStrForMsLogLevel(MsLogLevel level) { - if (level == MsLogLevel::DEBUG) { + if (level == MsLogLevel::kDebug) { return "DEBUG"; - } else if (level == MsLogLevel::INFO) { + } else if (level == MsLogLevel::kInfo) { return "INFO"; - } else if (level == MsLogLevel::WARNING) { + } else if (level == MsLogLevel::kWarning) { return "WARNING"; - } else if (level == MsLogLevel::ERROR) { + } else if (level == MsLogLevel::kError) { return "ERROR"; } else { return "NO_LEVEL"; @@ -127,13 +127,13 @@ const char *EnumStrForMsLogLevel(MsLogLevel level) { #if defined(__ANDROID__) || defined(ANDROID) static int GetAndroidLogLevel(MsLogLevel level) { switch (level) { - case MsLogLevel::DEBUG: + case MsLogLevel::kDebug: return ANDROID_LOG_DEBUG; - case MsLogLevel::INFO: + case MsLogLevel::kInfo: return ANDROID_LOG_INFO; - case MsLogLevel::WARNING: + case MsLogLevel::kWarning: return ANDROID_LOG_WARN; - case MsLogLevel::ERROR: + case MsLogLevel::kError: default: return ANDROID_LOG_ERROR; } @@ -152,14 +152,14 @@ static int GetAndroidLogLevel(MsLogLevel level) { // convert MsLogLevel to corresponding slog level static int GetSlogLevel(MsLogLevel level) { switch (level) { - case DEBUG: + case MsLogLevel::kDebug: return DLOG_DEBUG; - case INFO: + case MsLogLevel::kInfo: return DLOG_INFO; - case WARNING: + case MsLogLevel::kWarning: return DLOG_WARN; - case ERROR: - case EXCEPTION: + case MsLogLevel::kError: + case MsLogLevel::kException: default: return DLOG_ERROR; } @@ -379,7 +379,7 @@ void LogWriter::operator^(const LogStream &stream) const { thread_local bool running = false; if (!running) { running = true; - if (this_thread_max_log_level >= EXCEPTION) { + if (this_thread_max_log_level >= MsLogLevel::kException) { RemoveLabelBeforeOutputLog(msg); } if (trace_provider_ != nullptr) { @@ -578,7 +578,7 @@ bool ParseLogLevel(const std::string &str_level, MsLogLevel *ptr_level) { int ch = str_level.c_str()[0]; constexpr char number_start = '0'; ch = ch - number_start; // subtract ASCII code of '0', which is 48 - if (ch >= static_cast(DEBUG) && ch <= static_cast(EXCEPTION)) { + if (ch >= static_cast(MsLogLevel::kDebug) && ch <= static_cast(MsLogLevel::kException)) { if (ptr_level != nullptr) { *ptr_level = static_cast(ch); } @@ -592,13 +592,13 @@ static MsLogLevel GetGlobalLogLevel() { #ifdef USE_GLOG return static_cast(FLAGS_v); #else - int log_level = WARNING; // set default log level to WARNING + int log_level = MsLogLevel::kWarning; // set default log level to WARNING auto str_level = GetEnv("GLOG_v"); if (str_level.size() == 1) { int ch = str_level.c_str()[0]; constexpr char number_start = '0'; ch = ch - number_start; // subtract ASCII code of '0', which is 48 - if (ch >= DEBUG && ch <= EXCEPTION) { + if (ch >= MsLogLevel::kDebug && ch <= MsLogLevel::kException) { log_level = ch; } } @@ -725,7 +725,7 @@ MS_CORE_API void common_log_init(void) { FLAGS_logbufsecs = 0; // Set default log level to WARNING if (mindspore::GetEnv("GLOG_v").empty()) { - FLAGS_v = static_cast(mindspore::WARNING); + FLAGS_v = static_cast(mindspore::MsLogLevel::kWarning); } // Set default log file mode to 0640 diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index 408ba30e755..d67c79b48e5 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -38,6 +38,9 @@ #else #include "toolchain/slog.h" #endif + +#undef SM_DEBUG + // NOTICE: when relative path of 'log_adapter.h' changed, macro 'LOG_HDR_FILE_REL_PATH' must be changed #define LOG_HDR_FILE_REL_PATH "mindspore/core/utils/log_adapter.h" @@ -157,7 +160,7 @@ class LogStream { std::shared_ptr sstream_; }; -enum MsLogLevel : int { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION }; +enum MsLogLevel : int { kDebug = 0, kInfo, kWarning, kError, kException }; enum SubModuleId : int { SM_UNKNOWN = 0, // unknown submodule @@ -229,7 +232,7 @@ MS_EXPORT extern enum MsLogLevel this_thread_max_log_level; MS_EXPORT extern thread_local enum MsLogLevel this_thread_max_log_level; class TryCatchGuard { public: - TryCatchGuard() : origin_log_level_(this_thread_max_log_level) { this_thread_max_log_level = MsLogLevel::WARNING; } + TryCatchGuard() : origin_log_level_(this_thread_max_log_level) { this_thread_max_log_level = MsLogLevel::kWarning; } ~TryCatchGuard() { this_thread_max_log_level = origin_log_level_; } private: @@ -284,13 +287,13 @@ class MS_CORE_API LogWriter { excp_type) < mindspore::LogStream() #if !defined(BUILD_LITE_INFERENCE) || defined(BUILD_CORE_RUNTIME) -#define MSLOG_THROW(excp_type) \ - mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::EXCEPTION, SUBMODULE_ID, \ - excp_type) ^ \ +#define MSLOG_THROW(excp_type) \ + mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::kException, \ + SUBMODULE_ID, excp_type) ^ \ mindspore::LogStream() #else -#define MSLOG_THROW(excp_type) \ - mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::ERROR, SUBMODULE_ID, \ +#define MSLOG_THROW(excp_type) \ + mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::kError, SUBMODULE_ID, \ excp_type) < mindspore::LogStream() #endif @@ -301,10 +304,10 @@ inline bool IS_OUTPUT_ON(enum MsLogLevel level) noexcept(true) { #define MS_LOG(level) MS_LOG_##level -#define MS_LOG_DEBUG MSLOG_IF(mindspore::DEBUG, IS_OUTPUT_ON(mindspore::DEBUG), mindspore::NoExceptionType) -#define MS_LOG_INFO MSLOG_IF(mindspore::INFO, IS_OUTPUT_ON(mindspore::INFO), mindspore::NoExceptionType) -#define MS_LOG_WARNING MSLOG_IF(mindspore::WARNING, IS_OUTPUT_ON(mindspore::WARNING), mindspore::NoExceptionType) -#define MS_LOG_ERROR MSLOG_IF(mindspore::ERROR, IS_OUTPUT_ON(mindspore::ERROR), mindspore::NoExceptionType) +#define MS_LOG_DEBUG MSLOG_IF(mindspore::kDebug, IS_OUTPUT_ON(mindspore::kDebug), mindspore::NoExceptionType) +#define MS_LOG_INFO MSLOG_IF(mindspore::kInfo, IS_OUTPUT_ON(mindspore::kInfo), mindspore::NoExceptionType) +#define MS_LOG_WARNING MSLOG_IF(mindspore::kWarning, IS_OUTPUT_ON(mindspore::kWarning), mindspore::NoExceptionType) +#define MS_LOG_ERROR MSLOG_IF(mindspore::kError, IS_OUTPUT_ON(mindspore::kError), mindspore::NoExceptionType) #define MS_LOG_EXCEPTION MSLOG_THROW(mindspore::NoExceptionType) #define MS_EXCEPTION(type) MSLOG_THROW(type)