Fixed Windows build
This commit is contained in:
parent
6d527883ea
commit
3ded7424a7
@ -1,5 +1,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <array>
|
||||||
#include "log/LogUtils.h"
|
#include "log/LogUtils.h"
|
||||||
#include "misc/memtracker.h"
|
#include "misc/memtracker.h"
|
||||||
#include "Properties.h"
|
#include "Properties.h"
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#include "LogSinks.h"
|
#include "LogSinks.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <spdlog/formatter.h>
|
#include <spdlog/formatter.h>
|
||||||
|
#include <ctime>
|
||||||
|
#include <array>
|
||||||
|
#include <spdlog/details/os.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace spdlog;
|
using namespace spdlog;
|
||||||
@ -49,6 +52,7 @@ namespace logger {
|
|||||||
dest.resize(dest.size() + length);
|
dest.resize(dest.size() + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_CXX_TERMINAL
|
||||||
static constexpr std::array<std::string_view, spdlog::level::off + 1> level_mapping_colored{
|
static constexpr std::array<std::string_view, spdlog::level::off + 1> level_mapping_colored{
|
||||||
" [" ANSI_LIGHT_BLUE "TRACE" ANSI_RESET "] ",
|
" [" ANSI_LIGHT_BLUE "TRACE" ANSI_RESET "] ",
|
||||||
" [" ANSI_LIGHT_BLUE "DEBUG" ANSI_RESET "] ",
|
" [" ANSI_LIGHT_BLUE "DEBUG" ANSI_RESET "] ",
|
||||||
@ -58,6 +62,7 @@ namespace logger {
|
|||||||
" [" ANSI_RED ANSI_BOLD ANSI_REVERSE "CRITICAL" ANSI_RESET "] ",
|
" [" ANSI_RED ANSI_BOLD ANSI_REVERSE "CRITICAL" ANSI_RESET "] ",
|
||||||
" [" ANSI_GRAY "OFF " ANSI_RESET "] "
|
" [" ANSI_GRAY "OFF " ANSI_RESET "] "
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static constexpr std::array<std::string_view, spdlog::level::off + 1> level_mapping{
|
static constexpr std::array<std::string_view, spdlog::level::off + 1> level_mapping{
|
||||||
" [TRACE] ",
|
" [TRACE] ",
|
||||||
@ -70,7 +75,7 @@ namespace logger {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void LogFormatter::format(const details::log_msg &msg, memory_buf_t &dest) {
|
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();
|
dest.clear();
|
||||||
auto prefix_begin = dest.end();
|
auto prefix_begin = dest.end();
|
||||||
@ -83,8 +88,11 @@ namespace logger {
|
|||||||
|
|
||||||
//Level
|
//Level
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_CXX_TERMINAL
|
||||||
const auto& mapping = this->_colored ? level_mapping_colored : level_mapping;
|
const auto& mapping = this->_colored ? level_mapping_colored : level_mapping;
|
||||||
|
#else
|
||||||
|
const auto& mapping = level_mapping;
|
||||||
|
#endif
|
||||||
size_t level = msg.level.value;
|
size_t level = msg.level.value;
|
||||||
if(level >= mapping.size())
|
if(level >= mapping.size())
|
||||||
level = mapping.size() - 1;
|
level = mapping.size() - 1;
|
||||||
@ -100,7 +108,11 @@ namespace logger {
|
|||||||
found = payload.find(spdlog::details::os::default_eol, index);
|
found = payload.find(spdlog::details::os::default_eol, index);
|
||||||
auto line = payload.substr(index, (found == -1 ? payload.length() : found) - 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});
|
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());
|
dest.append(colored.data(), colored.data() + colored.size());
|
||||||
|
|
||||||
index = found;
|
index = found;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <CXXTerminal/Terminal.h>
|
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
#include <StringVariable.h>
|
#include <StringVariable.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -12,6 +11,10 @@
|
|||||||
#include <spdlog/async.h>
|
#include <spdlog/async.h>
|
||||||
#include <spdlog/sinks/rotating_file_sink.h>
|
#include <spdlog/sinks/rotating_file_sink.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CXX_TERMINAL
|
||||||
|
#include <CXXTerminal/Terminal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using namespace spdlog;
|
using namespace spdlog;
|
||||||
@ -42,7 +45,7 @@ namespace logger {
|
|||||||
logger->set_level(min_level);
|
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,
|
return strvar::transform(logConfig->logPath,
|
||||||
strvar::StringValue{"group", group != -1 ? to_string(group) : "general"},
|
strvar::StringValue{"group", group != -1 ? to_string(group) : "general"},
|
||||||
strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque<std::string> value) -> std::string {
|
strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque<std::string> value) -> std::string {
|
||||||
@ -118,7 +121,11 @@ namespace logger {
|
|||||||
if(group != 0 && group != -1)
|
if(group != 0 && group != -1)
|
||||||
logger(0)->critical("Failed to create file for new log group: {}", ex.what());
|
logger(0)->critical("Failed to create file for new log group: {}", ex.what());
|
||||||
else
|
else
|
||||||
|
#ifdef HAVE_CXX_TERMINAL
|
||||||
terminal::instance()->writeMessage("§4[CRITICAL] §eFailed to create main log file: " + string{ex.what()}, false);
|
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 {
|
} else {
|
||||||
path = "/dev/null (" + to_string(group) + ")";
|
path = "/dev/null (" + to_string(group) + ")";
|
||||||
|
Loading…
Reference in New Issue
Block a user