forked from mindspore-Ecosystem/mindspore
!1155 fix bug of log interface
Merge pull request !1155 from fary86/fix_bug_of_log_interface
This commit is contained in:
commit
cf6a4fe687
|
@ -82,11 +82,10 @@ set_target_properties(_c_dataengine PROPERTIES
|
|||
######################################################################
|
||||
|
||||
################# Link with external libraries ########################
|
||||
target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar)
|
||||
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})
|
||||
else()
|
||||
target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar)
|
||||
target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module -ldl mindspore::protobuf ${SECUREC_LIBRARY})
|
||||
endif()
|
||||
target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::opencv_core mindspore::opencv_imgcodecs
|
||||
|
|
|
@ -47,5 +47,6 @@ if (ENABLE_GPU)
|
|||
# add_library(_mindspore_device_cuda_obj OBJECT ${CUDA_SRC_LIST})
|
||||
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})
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* 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)
|
|||
# add_library(_mindspore_kernel_cuda_obj OBJECT ${CUDA_SRC_LIST})
|
||||
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})
|
||||
|
|
|
@ -28,7 +28,7 @@ set_target_properties(_c_mindrecord PROPERTIES
|
|||
|
||||
# add link library
|
||||
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()
|
||||
target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore_gvar mindspore::protobuf)
|
||||
endif()
|
||||
|
|
|
@ -241,28 +241,6 @@ static std::string GetEnv(const std::string &envvar) {
|
|||
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 {
|
||||
INVALID, // indicate invalid token
|
||||
LEFT_BRACE, // '{'
|
||||
|
@ -449,7 +427,16 @@ static MsLogLevel GetGlobalLogLevel() {
|
|||
#ifdef USE_GLOG
|
||||
return static_cast<MsLogLevel>(FLAGS_v);
|
||||
#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
|
||||
}
|
||||
|
||||
|
@ -521,10 +508,7 @@ void mindspore_log_init(void) {
|
|||
FLAGS_logtostderr = true;
|
||||
MS_LOG(WARNING) << "`GLOG_log_dir` is not set, output log to screen.";
|
||||
}
|
||||
|
||||
mindspore::InitSubModulesLogLevel();
|
||||
#else
|
||||
mindspore::InitMsLogLevel();
|
||||
#endif
|
||||
mindspore::InitSubModulesLogLevel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,10 +125,11 @@ enum SubModuleId : int {
|
|||
#define SUBMODULE_ID mindspore::SubModuleId::SM_ME
|
||||
#endif
|
||||
|
||||
#ifndef USE_GLOG
|
||||
extern int g_mslog_level;
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
extern int g_ms_submodule_log_levels[] __attribute__((dllexport));
|
||||
#else
|
||||
extern int g_ms_submodule_log_levels[] __attribute__((visibility("default")));
|
||||
#endif
|
||||
|
||||
class LogWriter {
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue