Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Apr 11, 2020
1 parent 19a8eef commit c2d3c0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
14 changes: 5 additions & 9 deletions hikyuu_cpp/hikyuu/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Author: fasiondog
*/

#include "config.h"
#include "GlobalInitializer.h"
#include "Log.h"

Expand All @@ -27,6 +28,10 @@ LOG_LEVEL get_log_level() {
return g_log_level;
}

std::shared_ptr<spdlog::logger> getHikyuuLogger() {
return spdlog::get("hikyuu");
}

/**********************************************
* Use SPDLOG for logging
*********************************************/
Expand All @@ -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<spdlog::async_logger> getHikyuuLogger() {
return spdlog::get("hikyuu");
}

#else /* #if HKU_USE_SPDLOG_ASYNC_LOGGER */

void init_logger() {
Expand All @@ -66,10 +66,6 @@ void init_logger() {
spdlog::register_logger(logger);
}

std::shared_ptr<spdlog::logger> 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) {
Expand Down
13 changes: 7 additions & 6 deletions hikyuu_cpp/hikyuu/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

#include "config.h"

// clang-format off
#if USE_SPDLOG_LOGGER
#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
#if HKU_USE_SPDLOG_ASYNC_LOGGER
#include "spdlog/async.h"
#endif
#endif
// clang-format on

#include <fmt/ostream.h>
#include <fmt/format.h>
Expand Down Expand Up @@ -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<spdlog::async_logger> HKU_API getHikyuuLogger();
#else
std::shared_ptr<spdlog::logger> 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__)
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c2d3c0b

Please sign in to comment.