29#if CONSOLIX_USE_LOGIT == 1
32 : m_level(logit::LogLevel::LOG_LVL_TRACE), m_file(__FILE__),
34 m_function(logit::make_relative(__FILE__, LOGIT_BASE_PATH)) {
43 logit::LogLevel level,
44 const std::string& file,
46 const std::string& function)
47 : m_level(level), m_file(file), m_line(line), m_function(function) {
58# if defined(_WIN32) || defined(_WIN64)
59 auto str = utf8_to_cp866(
m_stream.str());
64# if CONSOLIX_USE_LOGIT == 1
65 if (LOGIT_IS_SINGLE_MODE(CONSOLIX_LOGIT_CONSOLE_INDEX)) {
66 LOGIT_STREAM_TRACE_TO(CONSOLIX_LOGIT_CONSOLE_INDEX) << str;
68 logit::LogStream(m_level, m_file, m_line, m_function, CONSOLIX_LOGIT_LOGGER_INDEX) << str;
71# if defined(_WIN32) || defined(_WIN64)
72 handle_ansi_colors_windows(str);
101#if CONSOLIX_USE_LOGIT == 1
102 logit::LogLevel m_level;
105 std::string m_function;
111 if (!message.empty()) {
112 if (message.back() ==
'\n') {
113 std::cout << message;
115 std::cout << message << std::endl;
120# if CONSOLIX_USE_LOGIT == 0 && (defined(_WIN32) || defined(_WIN64))
124 void handle_ansi_colors_windows(
const std::string& message)
const {
125 std::string::size_type start = 0;
126 std::string::size_type pos = 0;
128 HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
130 while ((pos = message.find(
"\033[", start)) != std::string::npos) {
133 std::cout << message.substr(start, pos - start);
137 std::string::size_type end_pos = message.find(
'm', pos);
138 if (end_pos != std::string::npos) {
140 std::string ansi_code = message.substr(pos + 2, end_pos - pos - 2);
141 apply_color_from_ansi_code(ansi_code, handle_stdout);
151 if (start < message.size()) {
152 std::cout << message.substr(start);
154 if (!message.empty()) std::cout << std::endl;
163 void apply_color_from_ansi_code(
const std::string& ansi_code, HANDLE handle_stdout)
const {
165 const int code = std::stoi(ansi_code);
188 SetConsoleTextAttribute(handle_stdout, color_value);