Просмотр исходного кода

Set Windows console to UTF-8, and prevent unexpected formatting

default_compile_flags
vector-of-bool 4 лет назад
Родитель
Сommit
88634e0be0
1 измененных файлов: 15 добавлений и 2 удалений
  1. +15
    -2
      src/dds/util/log.cpp

+ 15
- 2
src/dds/util/log.cpp Просмотреть файл



#include <ostream> #include <ostream>


#if _WIN32
#include <consoleapi2.h>
static void set_utf8_output() {
// 65'001 is the codepage id for UTF-8 output
::SetConsoleOutputCP(65'001);
}
#else
static void set_utf8_output() {
// Nothing on other platforms
}
#endif

void dds::log::log_print(dds::log::level l, std::string_view msg) noexcept { void dds::log::log_print(dds::log::level l, std::string_view msg) noexcept {
static auto logger = [] {
static auto logger_inst = [] {
auto logger = spdlog::default_logger_raw(); auto logger = spdlog::default_logger_raw();
logger->set_level(spdlog::level::trace); logger->set_level(spdlog::level::trace);
set_utf8_output();
return logger; return logger;
}(); }();


neo_assert_always(invariant, false, "Invalid log level", msg, int(l)); neo_assert_always(invariant, false, "Invalid log level", msg, int(l));
}(); }();


logger->log(lvl, msg);
logger_inst->log(lvl, "{}", msg);
} }

Загрузка…
Отмена
Сохранить