!40852 adapt ms.log to windows

Merge pull request !40852 from chenminmin/master
This commit is contained in:
i-robot 2022-08-29 01:14:55 +00:00 committed by Gitee
commit 1483877469
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
21 changed files with 104 additions and 94 deletions

View File

@ -1053,7 +1053,7 @@ std::vector<CNodePtr> KernelGraph::FindNodeByPrimitive(const std::vector<Primiti
} }
void KernelGraph::PrintGraphExecuteOrder() const { void KernelGraph::PrintGraphExecuteOrder() const {
if (!(IS_OUTPUT_ON(INFO))) { if (!(IS_OUTPUT_ON(mindspore::kInfo))) {
return; return;
} }
MS_LOG(INFO) << "Graph " << graph_id_ << " execution order:"; MS_LOG(INFO) << "Graph " << graph_id_ << " execution order:";

View File

@ -613,7 +613,7 @@ void DebugServices::CheckWatchpoints(std::vector<std::string> *const name, std::
if (tensor_list_size == 0) { if (tensor_list_size == 0) {
return; return;
} }
if (IS_OUTPUT_ON(INFO)) { if (IS_OUTPUT_ON(mindspore::kInfo)) {
wp_progress_enabled_ = true; wp_progress_enabled_ = true;
wp_progress_thread_ = wp_progress_thread_ =
std::make_unique<std::thread>([this, tensor_list_size]() { CheckWatchpointProgress(tensor_list_size); }); std::make_unique<std::thread>([this, tensor_list_size]() { CheckWatchpointProgress(tensor_list_size); });
@ -668,7 +668,7 @@ void DebugServices::CheckWatchpoints(std::vector<std::string> *const name, std::
MS_LOG(INFO) << "tensor_list byte size is " << tensor_list_byte_size / pow(10.0, 6.0) << " MB"; 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_LOG(INFO) << "CheckWatchpoints Took: " << std::fixed << std::setprecision(precision)
<< (ms_double.count()) / ms_to_s << "s"; << (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_enabled_ = false;
wp_progress_thread_->join(); wp_progress_thread_->join();
MS_LOG(INFO) << "Join wp_progress_thread_."; MS_LOG(INFO) << "Join wp_progress_thread_.";

View File

@ -106,7 +106,7 @@ class Optimizer : public std::enable_shared_from_this<Optimizer> {
run_only_once_ = run_only_once; run_only_once_ = run_only_once;
is_watch_renormalize_ = false; is_watch_renormalize_ = false;
is_untyped_generated_ = 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) { for (auto &iter : passes) {
const std::string &name = iter.first; const std::string &name = iter.first;

View File

@ -56,7 +56,7 @@ class Ensures : public EnsuresAccess<T, R> {
if (!R::Check(value_)) { if (!R::Check(value_)) {
LogStream contract_stream; LogStream contract_stream;
contract_stream << "contract error: " << signatory.extra_info << R::Desc(); 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 <class O, typename = std::enable_if_t<std::is_convertible_v<O, T>>> template <class O, typename = std::enable_if_t<std::is_convertible_v<O, T>>>

View File

@ -380,7 +380,7 @@ Status CacheAdminArgHandler::Validate() {
"Number of workers must be in range of 1 and " + std::to_string(max_num_workers) + "."); "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)."); return Status(StatusCode::kMDSyntaxError, "Log level must be in range (0..4).");
} }

View File

@ -37,7 +37,7 @@ Status NodeOffloadPass::OffloadNodes::Visit(std::shared_ptr<MapNode> node, bool
if ((manual_offload == ManualOffloadMode::kEnabled) || if ((manual_offload == ManualOffloadMode::kEnabled) ||
((auto_offload_ == true) && (manual_offload != ManualOffloadMode::kDisabled))) { ((auto_offload_ == true) && (manual_offload != ManualOffloadMode::kDisabled))) {
bool offload_supported = true; bool offload_supported = true;
if (IS_OUTPUT_ON(mindspore::INFO)) { if (IS_OUTPUT_ON(mindspore::kInfo)) {
std::string operations = "operations=["; std::string operations = "operations=[";
auto op_list = node->operations(); auto op_list = node->operations();
std::for_each(op_list.begin(), op_list.end(), [&](const auto &op) { std::for_each(op_list.begin(), op_list.end(), [&](const auto &op) {

View File

@ -36,7 +36,7 @@ PluginLoader::~PluginLoader() {
std::transform(plugins_.begin(), plugins_.end(), std::back_inserter(keys), [](const auto &p) { return p.first; }); std::transform(plugins_.begin(), plugins_.end(), std::back_inserter(keys), [](const auto &p) { return p.first; });
for (std::string &key : keys) { for (std::string &key : keys) {
Status rc = UnloadPlugin(key); Status rc = UnloadPlugin(key);
MSLOG_IF(ERROR, rc.IsError(), mindspore::NoExceptionType) << rc.ToString(); MSLOG_IF(MsLogLevel::kError, rc.IsError(), mindspore::NoExceptionType) << rc.ToString();
} }
} }

View File

@ -3018,7 +3018,7 @@ FunctionBlockPtr Parser::ParseWith(const FunctionBlockPtr &block, const py::obje
void Parser::PrintPhiArgMaps(const std::map<ParameterPtr, std::set<AnfNodePtr>> &phi_to_args, void Parser::PrintPhiArgMaps(const std::map<ParameterPtr, std::set<AnfNodePtr>> &phi_to_args,
const std::map<AnfNodePtr, std::set<ParameterPtr>> &arg_to_phis) { const std::map<AnfNodePtr, std::set<ParameterPtr>> &arg_to_phis) {
if (!IS_OUTPUT_ON(DEBUG)) { if (!IS_OUTPUT_ON(mindspore::kDebug)) {
return; return;
} }
std::ostringstream oss; std::ostringstream oss;
@ -3136,7 +3136,7 @@ std::shared_ptr<std::map<ParameterPtr, AnfNodePtr>> Parser::CollectRemovablePhiA
(*need_remove_phi_args)[phi] = *(args.begin()); (*need_remove_phi_args)[phi] = *(args.begin());
} }
} }
if (IS_OUTPUT_ON(DEBUG)) { if (IS_OUTPUT_ON(mindspore::kDebug)) {
size_t m = 0; size_t m = 0;
std::ostringstream oss; std::ostringstream oss;
oss << "=====================Need removed phis and args=====================" oss << "=====================Need removed phis and args====================="

View File

@ -38,7 +38,7 @@ void AnalysisSchedule::Schedule() {
MS_LOG(DEBUG) << "Success to exit."; 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); MS_EXCEPTION_IF_NULL(async_infer_task);
{ {
std::lock_guard<std::mutex> activeLock(activate_thread_lock_); std::lock_guard<std::mutex> activeLock(activate_thread_lock_);

View File

@ -57,7 +57,7 @@ class AnalysisSchedule {
void Wait(); void Wait();
void Add2Schedule(const AsyncInferTaskPtr &async_infer_task_ptr); void Add2Schedule(const AsyncInferTaskPtr &async_infer_task_ptr);
void WaitForRun() const; void WaitForRun() const;
void Yield(AsyncInferTask *asyncTask); void YieldTask(AsyncInferTask *asyncTask);
void EnterWaiting() { void EnterWaiting() {
{ {
@ -327,7 +327,7 @@ class AsyncInferTask {
AbstractBasePtr GetResult() { AbstractBasePtr GetResult() {
StaticAnalysisException::Instance().CheckException(); StaticAnalysisException::Instance().CheckException();
AnalysisSchedule::GetInstance().Yield(this); AnalysisSchedule::GetInstance().YieldTask(this);
std::unique_lock<std::mutex> lock(lock_); std::unique_lock<std::mutex> lock(lock_);
MS_LOG(DEBUG) << AnalysisSchedule::thread_id() << " waiting."; MS_LOG(DEBUG) << AnalysisSchedule::thread_id() << " waiting.";
condition_var_.wait(lock, [this] { return ready_; }); condition_var_.wait(lock, [this] { return ready_; });

View File

@ -70,10 +70,14 @@ void PyNativeExecutorTry(const std::function<void(T *ret, const Args &...)> &met
throw(std::runtime_error(ex.what())); throw(std::runtime_error(ex.what()));
} catch (...) { } catch (...) {
inst->ClearRes(); inst->ClearRes();
#ifndef _MSC_VER
auto exception_type = abi::__cxa_current_exception_type(); auto exception_type = abi::__cxa_current_exception_type();
MS_EXCEPTION_IF_NULL(exception_type); MS_EXCEPTION_IF_NULL(exception_type);
std::string ex_name(exception_type->name()); std::string ex_name(exception_type->name());
MS_LOG(EXCEPTION) << "Error occurred when compile graph. Exception name: " << ex_name; MS_LOG(EXCEPTION) << "Error occurred when compile graph. Exception name: " << ex_name;
#else
MS_LOG(EXCEPTION) << "Error occurred when compile graph.";
#endif
} }
} }
} // namespace } // namespace

View File

@ -138,13 +138,13 @@ void PrintInfo(const nlohmann::json &info, const std::string &job_name, const in
auto message = GetJsonValue<std::string>(info, kMessage); auto message = GetJsonValue<std::string>(info, kMessage);
if (level == 0) { if (level == 0) {
MS_LOG(DEBUG) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; MS_LOG(DEBUG) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
} else if (level == static_cast<int>(INFO)) { } else if (level == static_cast<int>(MsLogLevel::kInfo)) {
MS_LOG(INFO) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; MS_LOG(INFO) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
} else if (level == static_cast<int>(WARNING)) { } else if (level == static_cast<int>(MsLogLevel::kWarning)) {
MS_LOG(WARNING) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; MS_LOG(WARNING) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
} else if (level == static_cast<int>(ERROR)) { } else if (level == static_cast<int>(MsLogLevel::kError)) {
MS_LOG(ERROR) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message; MS_LOG(ERROR) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
} else if (level == static_cast<int>(EXCEPTION)) { } else if (level == static_cast<int>(MsLogLevel::kException)) {
ReportToErrorManager(message); ReportToErrorManager(message);
} }
} }
@ -238,7 +238,8 @@ std::vector<std::string> GetTuneOpsList(const std::string &d) {
} }
} // namespace } // 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<std::vector<nlohmann::json>>(json, kProcessInfo); auto all_logs = GetJsonValue<std::vector<nlohmann::json>>(json, kProcessInfo);
auto job_id = GetJsonValue<int>(json, kJobId); auto job_id = GetJsonValue<int>(json, kJobId);
auto json_name = GetJsonValue<std::string>(json, kFusionOpName); auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
@ -590,7 +591,7 @@ std::string TbeKernelCompileManager::ParseSelectAndCheckResult(const nlohmann::j
return kFailed; return kFailed;
} }
if (res != kFullySupported) { if (res != kFullySupported) {
PrintProcessLog(json, static_cast<int>(DEBUG)); PrintProcessLog(json, static_cast<int>(MsLogLevel::kDebug));
} }
} else if (json.at(kStatus) == kFailed) { } else if (json.at(kStatus) == kFailed) {
auto all_logs = GetJsonValue<std::vector<nlohmann::json>>(json, kProcessInfo); auto all_logs = GetJsonValue<std::vector<nlohmann::json>>(json, kProcessInfo);

View File

@ -107,7 +107,7 @@ class TrtUtils {
class TrtLogger : public nvinfer1::ILogger { class TrtLogger : public nvinfer1::ILogger {
public: public:
TrtLogger() { 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"); const char *glog_config = std::getenv("GLOG_v");
if (glog_config == nullptr) { if (glog_config == nullptr) {
return; return;
@ -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::EXCEPTION) { if (ch >= MsLogLevel::kDebug && ch <= MsLogLevel::kException) {
log_level_ = static_cast<MsLogLevel>(ch); log_level_ = static_cast<MsLogLevel>(ch);
} }
} }
@ -127,11 +127,11 @@ class TrtLogger : public nvinfer1::ILogger {
#ifdef USE_GLOG #ifdef USE_GLOG
#define google mindspore_private #define google mindspore_private
static std::map<Severity, std::tuple<MsLogLevel, int, std::string>> logger_map = { static std::map<Severity, std::tuple<MsLogLevel, int, std::string>> logger_map = {
{Severity::kVERBOSE, {MsLogLevel::DEBUG, google::GLOG_INFO, "VERBOSE"}}, {Severity::kVERBOSE, {MsLogLevel::kDebug, google::GLOG_INFO, "VERBOSE"}},
{Severity::kINFO, {MsLogLevel::INFO, google::GLOG_INFO, "INFO"}}, {Severity::kINFO, {MsLogLevel::kInfo, google::GLOG_INFO, "INFO"}},
{Severity::kWARNING, {MsLogLevel::WARNING, google::GLOG_WARNING, "WARNING"}}, {Severity::kWARNING, {MsLogLevel::kWarning, google::GLOG_WARNING, "WARNING"}},
{Severity::kERROR, {MsLogLevel::ERROR, google::GLOG_ERROR, "ERROR"}}, {Severity::kERROR, {MsLogLevel::kError, google::GLOG_ERROR, "ERROR"}},
{Severity::kINTERNAL_ERROR, {MsLogLevel::ERROR, google::GLOG_ERROR, "INTERNAL ERROR"}}}; {Severity::kINTERNAL_ERROR, {MsLogLevel::kError, google::GLOG_ERROR, "INTERNAL ERROR"}}};
auto iter = logger_map.find(severity); auto iter = logger_map.find(severity);
if (iter == logger_map.end()) { if (iter == logger_map.end()) {

View File

@ -315,11 +315,11 @@ void TcpClient::Start() {
int ret = event_base_dispatch(event_base_); int ret = event_base_dispatch(event_base_);
// is_started_ should be false when finish dispatch // is_started_ should be false when finish dispatch
is_started_ = false; is_started_ = false;
MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base dispatch success!"; MSLOG_IF(MsLogLevel::kInfo, ret == 0, NoExceptionType) << "Event base dispatch success!";
MSLOG_IF(mindspore::ERROR, ret == 1, NoExceptionType) MSLOG_IF(MsLogLevel::kError, ret == 1, NoExceptionType)
<< "Event base dispatch failed with no events pending or active!"; << "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(MsLogLevel::kError, 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::kException, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!";
} }
void TcpClient::StartWithNoBlock() { void TcpClient::StartWithNoBlock() {
@ -327,10 +327,10 @@ void TcpClient::StartWithNoBlock() {
MS_LOG(INFO) << "Start tcp client with no block!"; MS_LOG(INFO) << "Start tcp client with no block!";
MS_EXCEPTION_IF_NULL(event_base_); MS_EXCEPTION_IF_NULL(event_base_);
int ret = event_base_loop(event_base_, EVLOOP_NONBLOCK); int ret = event_base_loop(event_base_, EVLOOP_NONBLOCK);
MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base loop success!"; MSLOG_IF(MsLogLevel::kInfo, 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(MsLogLevel::kError, 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(MsLogLevel::kError, 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::kException, ret < -1, AbortedError) << "Event base loop with unexpected error code!";
} }
void TcpClient::SetMessageCallback(const OnMessage &cb) { message_callback_ = cb; } void TcpClient::SetMessageCallback(const OnMessage &cb) { message_callback_ = cb; }

View File

@ -205,11 +205,11 @@ void TcpServer::Start() {
MS_LOG(INFO) << "Start tcp server!"; MS_LOG(INFO) << "Start tcp server!";
MS_EXCEPTION_IF_NULL(base_); MS_EXCEPTION_IF_NULL(base_);
int ret = event_base_dispatch(base_); int ret = event_base_dispatch(base_);
MSLOG_IF(INFO, ret == 0, NoExceptionType) << "Event base dispatch success!"; MSLOG_IF(MsLogLevel::kInfo, ret == 0, NoExceptionType) << "Event base dispatch success!";
MSLOG_IF(mindspore::ERROR, ret == 1, NoExceptionType) MSLOG_IF(MsLogLevel::kError, ret == 1, NoExceptionType)
<< "Event base dispatch failed with no events pending or active!"; << "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(MsLogLevel::kError, 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::kException, ret < -1, AbortedError) << "Event base dispatch with unexpected error code!";
} }
void TcpServer::Stop() { void TcpServer::Stop() {

View File

@ -58,8 +58,10 @@ else()
ms_protobuf_generate(PROTO_SRCS PROTO_HDRS ${PROTO_FILE}) ms_protobuf_generate(PROTO_SRCS PROTO_HDRS ${PROTO_FILE})
endif() 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") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -DHAVE_SNPRINTF")
endif()
add_compile_definitions(BUILDING_DLL) add_compile_definitions(BUILDING_DLL)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \

View File

@ -332,7 +332,7 @@ void SynchronizeSequenceNodesElementsUseFlagsInner(const AnfNodeWeakPtrList &seq
} }
void CheckSequenceNodesValid(const AnfNodeWeakPtrList &sequence_nodes) { void CheckSequenceNodesValid(const AnfNodeWeakPtrList &sequence_nodes) {
if (!IS_OUTPUT_ON(DEBUG)) { if (!IS_OUTPUT_ON(MsLogLevel::kDebug)) {
return; return;
} }
if (sequence_nodes.size() <= 1) { if (sequence_nodes.size() <= 1) {

View File

@ -25,7 +25,7 @@
#include "utils/macros.h" #include "utils/macros.h"
namespace mindspore::api { 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; class LogWriterImpl;
@ -90,11 +90,11 @@ class MIND_API LogWriter {
#define MIND_LOG_IF(L) \ #define MIND_LOG_IF(L) \
if (MIND_LOG_WRITER::IsEnabled(MIND_LOG_LEVEL(L))) MIND_LOG_WRITE(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_DEBUG MIND_LOG_IF(kDebug)
#define MIND_LOG_INFO MIND_LOG_IF(INFO) #define MIND_LOG_INFO MIND_LOG_IF(kInfo)
#define MIND_LOG_WARNING MIND_LOG_IF(WARNING) #define MIND_LOG_WARNING MIND_LOG_IF(kWarning)
#define MIND_LOG_ERROR MIND_LOG_IF(ERROR) #define MIND_LOG_ERROR MIND_LOG_IF(kError)
#define MIND_LOG_EXCEPTION MIND_LOG_THROW(EXCEPTION) #define MIND_LOG_EXCEPTION MIND_LOG_THROW(kException)
#define MIND_LOG(level) MIND_LOG_##level #define MIND_LOG(level) MIND_LOG_##level
#if !defined(MIND_LOG_NO_MS_LOG) && !defined(MS_LOG) #if !defined(MIND_LOG_NO_MS_LOG) && !defined(MS_LOG)

View File

@ -22,18 +22,18 @@
namespace mindspore::api { namespace mindspore::api {
static MsLogLevel ToMsLogLevel(LogLevel level) { static MsLogLevel ToMsLogLevel(LogLevel level) {
switch (level) { switch (level) {
case LogLevel::DEBUG: case LogLevel::kDebug:
return MsLogLevel::DEBUG; return MsLogLevel::kDebug;
case LogLevel::INFO: case LogLevel::kInfo:
return MsLogLevel::INFO; return MsLogLevel::kInfo;
case LogLevel::WARNING: case LogLevel::kWarning:
return MsLogLevel::WARNING; return MsLogLevel::kWarning;
case LogLevel::ERROR: case LogLevel::kError:
return MsLogLevel::ERROR; return MsLogLevel::kError;
case LogLevel::EXCEPTION: case LogLevel::kException:
return MsLogLevel::EXCEPTION; return MsLogLevel::kException;
default: default:
return MsLogLevel::EXCEPTION; return MsLogLevel::kException;
} }
} }

View File

@ -40,11 +40,11 @@ constexpr auto kSplitLine = "\n-------------------------------------------------
constexpr const char *ANDROID_LOG_TAG = "MS_LITE"; constexpr const char *ANDROID_LOG_TAG = "MS_LITE";
#endif #endif
// set default log level to WARNING for all sub modules // 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) #if defined(_WIN32) || defined(_WIN64)
enum MsLogLevel this_thread_max_log_level = EXCEPTION; enum MsLogLevel this_thread_max_log_level = MsLogLevel::kException;
#else #else
thread_local enum MsLogLevel this_thread_max_log_level = EXCEPTION; thread_local enum MsLogLevel this_thread_max_log_level = MsLogLevel::kException;
#endif #endif
#ifdef USE_GLOG #ifdef USE_GLOG
@ -82,13 +82,13 @@ static std::string GetLogLevel(MsLogLevel level) {
// convert MsLogLevel to corresponding glog level // convert MsLogLevel to corresponding glog level
static int GetGlogLevel(MsLogLevel level) { static int GetGlogLevel(MsLogLevel level) {
switch (level >= this_thread_max_log_level ? this_thread_max_log_level : level) { switch (level >= this_thread_max_log_level ? this_thread_max_log_level : level) {
case DEBUG: case MsLogLevel::kDebug:
case INFO: case MsLogLevel::kInfo:
return google::GLOG_INFO; return google::GLOG_INFO;
case WARNING: case MsLogLevel::kWarning:
return google::GLOG_WARNING; return google::GLOG_WARNING;
case ERROR: case MsLogLevel::kError:
case EXCEPTION: case MsLogLevel::kException:
default: default:
return google::GLOG_ERROR; return google::GLOG_ERROR;
} }
@ -111,13 +111,13 @@ static int GetThresholdLevel(const std::string &threshold) {
#undef google #undef google
#elif defined(BUILD_CORE_RUNTIME) #elif defined(BUILD_CORE_RUNTIME)
const char *EnumStrForMsLogLevel(MsLogLevel level) { const char *EnumStrForMsLogLevel(MsLogLevel level) {
if (level == MsLogLevel::DEBUG) { if (level == MsLogLevel::kDebug) {
return "DEBUG"; return "DEBUG";
} else if (level == MsLogLevel::INFO) { } else if (level == MsLogLevel::kInfo) {
return "INFO"; return "INFO";
} else if (level == MsLogLevel::WARNING) { } else if (level == MsLogLevel::kWarning) {
return "WARNING"; return "WARNING";
} else if (level == MsLogLevel::ERROR) { } else if (level == MsLogLevel::kError) {
return "ERROR"; return "ERROR";
} else { } else {
return "NO_LEVEL"; return "NO_LEVEL";
@ -127,13 +127,13 @@ const char *EnumStrForMsLogLevel(MsLogLevel level) {
#if defined(__ANDROID__) || defined(ANDROID) #if defined(__ANDROID__) || defined(ANDROID)
static int GetAndroidLogLevel(MsLogLevel level) { static int GetAndroidLogLevel(MsLogLevel level) {
switch (level) { switch (level) {
case MsLogLevel::DEBUG: case MsLogLevel::kDebug:
return ANDROID_LOG_DEBUG; return ANDROID_LOG_DEBUG;
case MsLogLevel::INFO: case MsLogLevel::kInfo:
return ANDROID_LOG_INFO; return ANDROID_LOG_INFO;
case MsLogLevel::WARNING: case MsLogLevel::kWarning:
return ANDROID_LOG_WARN; return ANDROID_LOG_WARN;
case MsLogLevel::ERROR: case MsLogLevel::kError:
default: default:
return ANDROID_LOG_ERROR; return ANDROID_LOG_ERROR;
} }
@ -152,14 +152,14 @@ static int GetAndroidLogLevel(MsLogLevel level) {
// convert MsLogLevel to corresponding slog level // convert MsLogLevel to corresponding slog level
static int GetSlogLevel(MsLogLevel level) { static int GetSlogLevel(MsLogLevel level) {
switch (level) { switch (level) {
case DEBUG: case MsLogLevel::kDebug:
return DLOG_DEBUG; return DLOG_DEBUG;
case INFO: case MsLogLevel::kInfo:
return DLOG_INFO; return DLOG_INFO;
case WARNING: case MsLogLevel::kWarning:
return DLOG_WARN; return DLOG_WARN;
case ERROR: case MsLogLevel::kError:
case EXCEPTION: case MsLogLevel::kException:
default: default:
return DLOG_ERROR; return DLOG_ERROR;
} }
@ -379,7 +379,7 @@ void LogWriter::operator^(const LogStream &stream) const {
thread_local bool running = false; thread_local bool running = false;
if (!running) { if (!running) {
running = true; running = true;
if (this_thread_max_log_level >= EXCEPTION) { if (this_thread_max_log_level >= MsLogLevel::kException) {
RemoveLabelBeforeOutputLog(msg); RemoveLabelBeforeOutputLog(msg);
} }
if (trace_provider_ != nullptr) { 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]; int ch = str_level.c_str()[0];
constexpr char number_start = '0'; constexpr char number_start = '0';
ch = ch - number_start; // subtract ASCII code of '0', which is 48 ch = ch - number_start; // subtract ASCII code of '0', which is 48
if (ch >= static_cast<int>(DEBUG) && ch <= static_cast<int>(EXCEPTION)) { if (ch >= static_cast<int>(MsLogLevel::kDebug) && ch <= static_cast<int>(MsLogLevel::kException)) {
if (ptr_level != nullptr) { if (ptr_level != nullptr) {
*ptr_level = static_cast<MsLogLevel>(ch); *ptr_level = static_cast<MsLogLevel>(ch);
} }
@ -592,13 +592,13 @@ static MsLogLevel GetGlobalLogLevel() {
#ifdef USE_GLOG #ifdef USE_GLOG
return static_cast<MsLogLevel>(FLAGS_v); return static_cast<MsLogLevel>(FLAGS_v);
#else #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"); auto str_level = GetEnv("GLOG_v");
if (str_level.size() == 1) { if (str_level.size() == 1) {
int ch = str_level.c_str()[0]; int ch = str_level.c_str()[0];
constexpr char number_start = '0'; constexpr char number_start = '0';
ch = ch - number_start; // subtract ASCII code of '0', which is 48 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; log_level = ch;
} }
} }
@ -725,7 +725,7 @@ MS_CORE_API void common_log_init(void) {
FLAGS_logbufsecs = 0; FLAGS_logbufsecs = 0;
// Set default log level to WARNING // Set default log level to WARNING
if (mindspore::GetEnv("GLOG_v").empty()) { if (mindspore::GetEnv("GLOG_v").empty()) {
FLAGS_v = static_cast<int>(mindspore::WARNING); FLAGS_v = static_cast<int>(mindspore::MsLogLevel::kWarning);
} }
// Set default log file mode to 0640 // Set default log file mode to 0640

View File

@ -38,6 +38,9 @@
#else #else
#include "toolchain/slog.h" #include "toolchain/slog.h"
#endif #endif
#undef SM_DEBUG
// NOTICE: when relative path of 'log_adapter.h' changed, macro 'LOG_HDR_FILE_REL_PATH' must be changed // 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" #define LOG_HDR_FILE_REL_PATH "mindspore/core/utils/log_adapter.h"
@ -157,7 +160,7 @@ class LogStream {
std::shared_ptr<std::stringstream> sstream_; std::shared_ptr<std::stringstream> sstream_;
}; };
enum MsLogLevel : int { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION }; enum MsLogLevel : int { kDebug = 0, kInfo, kWarning, kError, kException };
enum SubModuleId : int { enum SubModuleId : int {
SM_UNKNOWN = 0, // unknown submodule 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; MS_EXPORT extern thread_local enum MsLogLevel this_thread_max_log_level;
class TryCatchGuard { class TryCatchGuard {
public: 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_; } ~TryCatchGuard() { this_thread_max_log_level = origin_log_level_; }
private: private:
@ -284,13 +287,13 @@ class MS_CORE_API LogWriter {
excp_type) < mindspore::LogStream() excp_type) < mindspore::LogStream()
#if !defined(BUILD_LITE_INFERENCE) || defined(BUILD_CORE_RUNTIME) #if !defined(BUILD_LITE_INFERENCE) || defined(BUILD_CORE_RUNTIME)
#define MSLOG_THROW(excp_type) \ #define MSLOG_THROW(excp_type) \
mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::EXCEPTION, SUBMODULE_ID, \ mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::kException, \
excp_type) ^ \ SUBMODULE_ID, excp_type) ^ \
mindspore::LogStream() mindspore::LogStream()
#else #else
#define MSLOG_THROW(excp_type) \ #define MSLOG_THROW(excp_type) \
mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::ERROR, SUBMODULE_ID, \ mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::kError, SUBMODULE_ID, \
excp_type) < mindspore::LogStream() excp_type) < mindspore::LogStream()
#endif #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(level) MS_LOG_##level
#define MS_LOG_DEBUG MSLOG_IF(mindspore::DEBUG, IS_OUTPUT_ON(mindspore::DEBUG), mindspore::NoExceptionType) #define MS_LOG_DEBUG MSLOG_IF(mindspore::kDebug, IS_OUTPUT_ON(mindspore::kDebug), mindspore::NoExceptionType)
#define MS_LOG_INFO MSLOG_IF(mindspore::INFO, IS_OUTPUT_ON(mindspore::INFO), mindspore::NoExceptionType) #define MS_LOG_INFO MSLOG_IF(mindspore::kInfo, IS_OUTPUT_ON(mindspore::kInfo), mindspore::NoExceptionType)
#define MS_LOG_WARNING MSLOG_IF(mindspore::WARNING, IS_OUTPUT_ON(mindspore::WARNING), mindspore::NoExceptionType) #define MS_LOG_WARNING MSLOG_IF(mindspore::kWarning, IS_OUTPUT_ON(mindspore::kWarning), mindspore::NoExceptionType)
#define MS_LOG_ERROR MSLOG_IF(mindspore::ERROR, IS_OUTPUT_ON(mindspore::ERROR), 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_LOG_EXCEPTION MSLOG_THROW(mindspore::NoExceptionType)
#define MS_EXCEPTION(type) MSLOG_THROW(type) #define MS_EXCEPTION(type) MSLOG_THROW(type)