Skip to content

Commit

Permalink
Merge pull request #2038 from KomodoPlatform/ensure-debug-logs-not-in…
Browse files Browse the repository at this point in the history
…-release

Make sure debug logs are not shown on release builds
  • Loading branch information
syl authored Nov 1, 2022
2 parents c2de8b9 + 9990759 commit 61bd49a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 49 deletions.
37 changes: 27 additions & 10 deletions src/app/main.prerequisites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,34 @@ clean_previous_run()
atomic_dex::kill_executable(atomic_dex::g_dex_api);
}

static void
init_logging()
static void init_logging()
{
auto logger = atomic_dex::utils::register_logger();
if (spdlog::get("log_mt") == nullptr)
{
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
spdlog::set_level(spdlog::level::trace);
spdlog::set_pattern("[%T] [%^%l%$] [%s:%#] [%t]: %v");
}
constexpr size_t qsize_spdlog = 10240;
constexpr size_t spdlog_thread_count = 2;
constexpr size_t spdlog_max_file_size = 7777777;
constexpr size_t spdlog_max_file_rotation = 3;

fs::path path = atomic_dex::utils::get_atomic_dex_current_log_file();
spdlog::init_thread_pool(qsize_spdlog, spdlog_thread_count);
auto tp = spdlog::thread_pool();
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();

#if defined(_WIN32) || defined(WIN32)
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(path.wstring(), spdlog_max_file_size, spdlog_max_file_rotation);
#else
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(path.string(), spdlog_max_file_size, spdlog_max_file_rotation);
#endif

std::vector<spdlog::sink_ptr> sinks{stdout_sink, rotating_sink};
auto logger = std::make_shared<spdlog::async_logger>("log_mt", sinks.begin(), sinks.end(), tp, spdlog::async_overflow_policy::block);
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
#ifdef DEBUG
spdlog::set_level(spdlog::level::trace);
#else
spdlog::set_level(spdlog::level::info);
#endif
spdlog::set_pattern("[%T] [%^%l%$] [%s:%#] [%t]: %v");
}

static void
Expand Down
31 changes: 0 additions & 31 deletions src/core/atomicdex/utilities/global.utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

namespace
{
constexpr size_t g_qsize_spdlog = 10240;
constexpr size_t g_spdlog_thread_count = 2;
constexpr size_t g_spdlog_max_file_size = 7777777;
constexpr size_t g_spdlog_max_file_rotation = 3;

std::string
dex_sha256(const std::string& str)
{
Expand Down Expand Up @@ -232,32 +227,6 @@ namespace atomic_dex::utils
return fs_raw_mm2_shared_folder;
}

std::shared_ptr<spdlog::logger>
register_logger()
{
//! Log Initialization
fs::path path = atomic_dex::utils::get_atomic_dex_current_log_file();
spdlog::init_thread_pool(g_qsize_spdlog, g_spdlog_thread_count);
auto tp = spdlog::thread_pool();
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();

#if defined(_WIN32) || defined(WIN32)
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(path.wstring(), g_spdlog_max_file_size, g_spdlog_max_file_rotation);
#else
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(path.string(), g_spdlog_max_file_size, g_spdlog_max_file_rotation);
#endif

std::vector<spdlog::sink_ptr> sinks{stdout_sink, rotating_sink};
auto logger = std::make_shared<spdlog::async_logger>("log_mt", sinks.begin(), sinks.end(), tp, spdlog::async_overflow_policy::block);
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
spdlog::set_level(spdlog::level::trace);
spdlog::set_pattern("[%T] [%^%l%$] [%s:%#] [%t]: %v");
SPDLOG_INFO("Logger successfully initialized");

return logger;
}

std::string
extract_large_float(const std::string& current)
{
Expand Down
1 change: 0 additions & 1 deletion src/core/atomicdex/utilities/global.utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ namespace atomic_dex::utils
fs::path get_atomic_dex_logs_folder() ;

ENTT_API fs::path get_atomic_dex_current_log_file();
ENTT_API std::shared_ptr<spdlog::logger> register_logger();

ENTT_API fs::path get_current_configs_path();

Expand Down
14 changes: 9 additions & 5 deletions src/core/atomicdex/utilities/log.prerequisites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#endif
#endif

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#ifdef DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#else
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#endif
#include <spdlog/async.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
Expand All @@ -34,9 +38,9 @@
#endif

#if defined(_WIN32) || defined(WIN32)
#define LOG_PATH(message, p) SPDLOG_INFO(L"" message, p.wstring());
#define LOG_PATH_CMP(message, from, to) SPDLOG_INFO(L"" message, from.wstring(), to.wstring());
#define LOG_PATH(message, p) SPDLOG_INFO(L"" message, p.wstring());
#define LOG_PATH_CMP(message, from, to) SPDLOG_INFO(L"" message, from.wstring(), to.wstring());
#else
#define LOG_PATH(message, p) SPDLOG_INFO(message, p.string());
#define LOG_PATH_CMP(message, from, to) SPDLOG_INFO(message, from.string(), to.string());
#define LOG_PATH(message, p) SPDLOG_INFO(message, p.string());
#define LOG_PATH_CMP(message, from, to) SPDLOG_INFO(message, from.string(), to.string());
#endif
2 changes: 0 additions & 2 deletions src/tests/utilities/global.utilities.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ TEST_CASE("atomic_dex::utils::get_runtime_coins_path()")
CHECK(fs::exists(result));
}

TEST_CASE("atomic_dex::utils::register_logger()") { CHECK_NE(register_logger(), nullptr); }

TEST_CASE("atomic_dex::utils::get_current_configs_path()")
{
auto result = get_current_configs_path();
Expand Down

0 comments on commit 61bd49a

Please sign in to comment.