diff --git a/hikyuu_cpp/hikyuu/Log.cpp b/hikyuu_cpp/hikyuu/Log.cpp index be6a05a34..f8de6fe9d 100644 --- a/hikyuu_cpp/hikyuu/Log.cpp +++ b/hikyuu_cpp/hikyuu/Log.cpp @@ -5,6 +5,7 @@ * Author: fasiondog */ +#include "config.h" #include "GlobalInitializer.h" #include "Log.h" @@ -27,6 +28,10 @@ LOG_LEVEL get_log_level() { return g_log_level; } +std::shared_ptr getHikyuuLogger() { + return spdlog::get("hikyuu"); +} + /********************************************** * Use SPDLOG for logging *********************************************/ @@ -45,15 +50,10 @@ void init_logger() { logger->set_level(spdlog::level::trace); logger->flush_on(spdlog::level::trace); - // logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v [%!]"); logger->set_pattern("%Y-%m-%d %H:%M:%S.%e [%^HKU-%L%$] - %v [%!]"); spdlog::register_logger(logger); } -std::shared_ptr getHikyuuLogger() { - return spdlog::get("hikyuu"); -} - #else /* #if HKU_USE_SPDLOG_ASYNC_LOGGER */ void init_logger() { @@ -66,10 +66,6 @@ void init_logger() { spdlog::register_logger(logger); } -std::shared_ptr HKU_API getHikyuuLogger() { - return spdlog::get("hikyuu"); // inner::g_hikyuu_logger; -} - #endif /* #if HKU_USE_SPDLOG_ASYNC_LOGGER */ void set_log_level(LOG_LEVEL level) { diff --git a/hikyuu_cpp/hikyuu/Log.h b/hikyuu_cpp/hikyuu/Log.h index 17dc8a7ef..e9dbb4b2d 100644 --- a/hikyuu_cpp/hikyuu/Log.h +++ b/hikyuu_cpp/hikyuu/Log.h @@ -11,10 +11,15 @@ #include "config.h" +// clang-format off #if USE_SPDLOG_LOGGER -#include -#include + #include + #include + #if HKU_USE_SPDLOG_ASYNC_LOGGER + #include "spdlog/async.h" + #endif #endif +// clang-format on #include #include @@ -60,11 +65,7 @@ LOG_LEVEL HKU_API get_log_level(); */ void HKU_API set_log_level(LOG_LEVEL level); -#if HKU_USE_SPDLOG_ASYNC_LOGGER -std::shared_ptr HKU_API getHikyuuLogger(); -#else std::shared_ptr HKU_API getHikyuuLogger(); -#endif /* #if HKU_USE_SPDLOG_ASYNC_LOGGER */ #define HKU_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) #define HKU_TRACE(...) SPDLOG_LOGGER_TRACE(hku::getHikyuuLogger(), __VA_ARGS__) diff --git a/xmake.lua b/xmake.lua index cfd0db35c..96fa03d5c 100644 --- a/xmake.lua +++ b/xmake.lua @@ -10,7 +10,7 @@ if is_mode("debug") then else set_configvar("LOG_ACTIVE_LEVEL", 2) -- 激活的日志级别 end -set_configvar("USE_SPDLOG_LOGGER", 0) -- 是否使用spdlog作为日志输出 +set_configvar("USE_SPDLOG_LOGGER", 1) -- 是否使用spdlog作为日志输出 set_configvar("USE_SPDLOG_ASYNC_LOGGER", 0) -- 使用异步的spdlog set_configvar("CHECK_ACCESS_BOUND", 1) set_configvar("SUPPORT_SERIALIZATION", is_mode("release") and 1 or 0)