提交 cf6a4fe6 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!1155 fix bug of log interface

Merge pull request !1155 from fary86/fix_bug_of_log_interface
...@@ -82,11 +82,10 @@ set_target_properties(_c_dataengine PROPERTIES ...@@ -82,11 +82,10 @@ set_target_properties(_c_dataengine PROPERTIES
###################################################################### ######################################################################
################# Link with external libraries ######################## ################# Link with external libraries ########################
target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(_c_dataengine PRIVATE mindspore)
target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} mindspore::protobuf ${SECUREC_LIBRARY}) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} mindspore::protobuf ${SECUREC_LIBRARY})
else() else()
target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar)
target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module -ldl mindspore::protobuf ${SECUREC_LIBRARY}) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module -ldl mindspore::protobuf ${SECUREC_LIBRARY})
endif() endif()
target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::opencv_core mindspore::opencv_imgcodecs target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::opencv_core mindspore::opencv_imgcodecs
......
...@@ -47,5 +47,6 @@ if (ENABLE_GPU) ...@@ -47,5 +47,6 @@ if (ENABLE_GPU)
# add_library(_mindspore_device_cuda_obj OBJECT ${CUDA_SRC_LIST}) # add_library(_mindspore_device_cuda_obj OBJECT ${CUDA_SRC_LIST})
endif () endif ()
set_property(SOURCE ${DEVICE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE) set_property(SOURCE ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST}
PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE)
add_library(_mindspore_device_obj OBJECT ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST}) add_library(_mindspore_device_obj OBJECT ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST})
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "utils/log_adapter.h"
namespace mindspore {
// set default log level to WARNING for all sub modules
int g_ms_submodule_log_levels[NUM_SUBMODUES] = {WARNING};
} // namespace mindspore
...@@ -43,5 +43,6 @@ if (ENABLE_GPU) ...@@ -43,5 +43,6 @@ if (ENABLE_GPU)
# add_library(_mindspore_kernel_cuda_obj OBJECT ${CUDA_SRC_LIST}) # add_library(_mindspore_kernel_cuda_obj OBJECT ${CUDA_SRC_LIST})
endif() endif()
set_property(SOURCE ${KERNEL_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL) set_property(SOURCE ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST}
PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL)
add_library(_mindspore_kernel_obj OBJECT ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST}) add_library(_mindspore_kernel_obj OBJECT ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST})
...@@ -28,7 +28,7 @@ set_target_properties(_c_mindrecord PROPERTIES ...@@ -28,7 +28,7 @@ set_target_properties(_c_mindrecord PROPERTIES
# add link library # add link library
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore::protobuf) target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore_gvar mindspore::protobuf)
else() else()
target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore_gvar mindspore::protobuf) target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore_gvar mindspore::protobuf)
endif() endif()
......
...@@ -241,28 +241,6 @@ static std::string GetEnv(const std::string &envvar) { ...@@ -241,28 +241,6 @@ static std::string GetEnv(const std::string &envvar) {
return std::string(value); return std::string(value);
} }
#ifndef USE_GLOG
// set default log warning to WARNING
int g_mslog_level = WARNING;
static void InitMsLogLevel() {
int log_level = WARNING; // set default log level to WARNING
auto str_level = GetEnv("GLOG_v");
if (str_level.size() == 1) {
int ch = str_level.c_str()[0];
ch = ch - '0'; // substract ASCII code of '0', which is 48
if (ch >= DEBUG && ch <= ERROR) {
log_level = ch;
}
}
g_mslog_level = log_level;
}
#endif
// set default log level to WARNING for all sub modules
int g_ms_submodule_log_levels[NUM_SUBMODUES] = {WARNING};
enum LogConfigToken { enum LogConfigToken {
INVALID, // indicate invalid token INVALID, // indicate invalid token
LEFT_BRACE, // '{' LEFT_BRACE, // '{'
...@@ -449,7 +427,16 @@ static MsLogLevel GetGlobalLogLevel() { ...@@ -449,7 +427,16 @@ static MsLogLevel GetGlobalLogLevel() {
#ifdef USE_GLOG #ifdef USE_GLOG
return static_cast<MsLogLevel>(FLAGS_v); return static_cast<MsLogLevel>(FLAGS_v);
#else #else
return static_cast<MsLogLevel>(g_mslog_level); int log_level = WARNING; // set default log level to WARNING
auto str_level = GetEnv("GLOG_v");
if (str_level.size() == 1) {
int ch = str_level.c_str()[0];
ch = ch - '0'; // substract ASCII code of '0', which is 48
if (ch >= DEBUG && ch <= ERROR) {
log_level = ch;
}
}
return static_cast<MsLogLevel>(log_level);
#endif #endif
} }
...@@ -521,10 +508,7 @@ void mindspore_log_init(void) { ...@@ -521,10 +508,7 @@ void mindspore_log_init(void) {
FLAGS_logtostderr = true; FLAGS_logtostderr = true;
MS_LOG(WARNING) << "`GLOG_log_dir` is not set, output log to screen."; MS_LOG(WARNING) << "`GLOG_log_dir` is not set, output log to screen.";
} }
mindspore::InitSubModulesLogLevel();
#else
mindspore::InitMsLogLevel();
#endif #endif
mindspore::InitSubModulesLogLevel();
} }
} }
...@@ -125,10 +125,11 @@ enum SubModuleId : int { ...@@ -125,10 +125,11 @@ enum SubModuleId : int {
#define SUBMODULE_ID mindspore::SubModuleId::SM_ME #define SUBMODULE_ID mindspore::SubModuleId::SM_ME
#endif #endif
#ifndef USE_GLOG #if defined(_WIN32) || defined(_WIN64)
extern int g_mslog_level; extern int g_ms_submodule_log_levels[] __attribute__((dllexport));
#endif #else
extern int g_ms_submodule_log_levels[] __attribute__((visibility("default"))); extern int g_ms_submodule_log_levels[] __attribute__((visibility("default")));
#endif
class LogWriter { class LogWriter {
public: public:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册