33#if CONSOLIX_USE_LOGIT == 1
36 : m_level(logit::LogLevel::LOG_LVL_TRACE),
39 m_function(logit::make_relative(__FILE__, LOGIT_BASE_PATH)) {
48 logit::LogLevel level,
49 const std::string& file,
51 const std::string& function)
52 : m_level(level), m_file(file), m_line(line), m_function(function) {
64 logit::LogLevel level,
65 const std::string& file,
67 const std::string& function,
68 std::initializer_list<int> logger_indices)
73 m_logger_indices(logger_indices) {
87# if CONSOLIX_USE_LOGIT == 1
88 auto str = utf8_to_cp866(
m_stream.str());
96# if CONSOLIX_USE_LOGIT == 1
97 if (LOGIT_IS_SINGLE_MODE(CONSOLIX_LOGIT_CONSOLE_INDEX)) {
98 logit::LogStream(m_level, m_file, m_line, m_function, CONSOLIX_LOGIT_CONSOLE_INDEX) << str;
100 logit::LogStream(m_level, m_file, m_line, m_function, CONSOLIX_LOGIT_LOGGER_INDEX) << str;
101 for (
int logger_index : m_logger_indices) {
102 logit::LogStream(m_level, m_file, m_line, m_function, logger_index) << str;
107 handle_ansi_colors_windows(str);
119 template <
typename T>
136#if CONSOLIX_USE_LOGIT == 1
137 logit::LogLevel m_level;
140 std::string m_function;
141 std::vector<int> m_logger_indices;
149 if (!message.empty()) {
150 if (message.back() ==
'\n') {
151 std::cout << message;
153 std::cout << message << std::endl;
158# if CONSOLIX_USE_LOGIT == 0 && defined(_WIN32)
162 void handle_ansi_colors_windows(
const std::string& message)
const {
163 std::string::size_type start = 0;
164 std::string::size_type pos = 0;
166 HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
168 while ((pos = message.find(
"\033[", start)) != std::string::npos) {
171 std::cout << message.substr(start, pos - start);
175 std::string::size_type end_pos = message.find(
'm', pos);
176 if (end_pos != std::string::npos) {
178 std::string ansi_code = message.substr(pos + 2, end_pos - pos - 2);
179 apply_color_from_ansi_code(ansi_code, handle_stdout);
189 if (start < message.size()) {
190 std::cout << message.substr(start);
192 if (!message.empty()) std::cout << std::endl;
201 void apply_color_from_ansi_code(
const std::string& ansi_code, HANDLE handle_stdout)
const {
203 const int code = std::stoi(ansi_code);
226 SetConsoleTextAttribute(handle_stdout, color_value);