From 3ded7424a79f2455266f6ef63bd83701058cb2e1 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 24 Nov 2019 23:23:07 +0100 Subject: [PATCH] Fixed Windows build --- src/Properties.cpp | 1 + src/log/LogSinks.cpp | 16 ++++++++++++++-- src/log/LogUtils.cpp | 11 +++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Properties.cpp b/src/Properties.cpp index a6216fe..969ae4c 100644 --- a/src/Properties.cpp +++ b/src/Properties.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "log/LogUtils.h" #include "misc/memtracker.h" #include "Properties.h" diff --git a/src/log/LogSinks.cpp b/src/log/LogSinks.cpp index 53640a5..b13ed0e 100644 --- a/src/log/LogSinks.cpp +++ b/src/log/LogSinks.cpp @@ -2,6 +2,9 @@ #include "LogSinks.h" #include #include +#include +#include +#include using namespace std; using namespace spdlog; @@ -49,6 +52,7 @@ namespace logger { dest.resize(dest.size() + length); } +#ifdef HAVE_CXX_TERMINAL static constexpr std::array level_mapping_colored{ " [" ANSI_LIGHT_BLUE "TRACE" ANSI_RESET "] ", " [" ANSI_LIGHT_BLUE "DEBUG" ANSI_RESET "] ", @@ -58,6 +62,7 @@ namespace logger { " [" ANSI_RED ANSI_BOLD ANSI_REVERSE "CRITICAL" ANSI_RESET "] ", " [" ANSI_GRAY "OFF " ANSI_RESET "] " }; +#endif static constexpr std::array level_mapping{ " [TRACE] ", @@ -70,7 +75,7 @@ namespace logger { }; void LogFormatter::format(const details::log_msg &msg, memory_buf_t &dest) { - const auto append = [&](const std::string_view& message) { dest.append(message.begin(), message.end()); }; + const auto append = [&](const std::string_view& message) { dest.append(message.data(), message.data() + message.length()); }; dest.clear(); auto prefix_begin = dest.end(); @@ -83,8 +88,11 @@ namespace logger { //Level { +#ifdef HAVE_CXX_TERMINAL const auto& mapping = this->_colored ? level_mapping_colored : level_mapping; - +#else + const auto& mapping = level_mapping; +#endif size_t level = msg.level.value; if(level >= mapping.size()) level = mapping.size() - 1; @@ -100,7 +108,11 @@ namespace logger { found = payload.find(spdlog::details::os::default_eol, index); auto line = payload.substr(index, (found == -1 ? payload.length() : found) - index); +#ifdef HAVE_CXX_TERMINAL auto colored = this->_colored ? terminal::parseCharacterCodes(std::string{line}) : terminal::stripCharacterCodes(std::string{line}); +#else + auto colored = line; +#endif dest.append(colored.data(), colored.data() + colored.size()); index = found; diff --git a/src/log/LogUtils.cpp b/src/log/LogUtils.cpp index 559b5bc..1a830e3 100644 --- a/src/log/LogUtils.cpp +++ b/src/log/LogUtils.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,10 @@ #include #include +#ifdef HAVE_CXX_TERMINAL + #include +#endif + using namespace std; using namespace std::chrono; using namespace spdlog; @@ -42,7 +45,7 @@ namespace logger { logger->set_level(min_level); } - std::string generate_log_file(int group) { + std::string generate_log_file(size_t group) { return strvar::transform(logConfig->logPath, strvar::StringValue{"group", group != -1 ? to_string(group) : "general"}, strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque value) -> std::string { @@ -118,7 +121,11 @@ namespace logger { if(group != 0 && group != -1) logger(0)->critical("Failed to create file for new log group: {}", ex.what()); else +#ifdef HAVE_CXX_TERMINAL terminal::instance()->writeMessage("§4[CRITICAL] §eFailed to create main log file: " + string{ex.what()}, false); +#else + std::cout << "[CRITICAL] Failed to create main log file: " << ex.what() << "\n"; +#endif } } else { path = "/dev/null (" + to_string(group) + ")";