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) {
65# if CONSOLIX_USE_LOGIT == 1
66 if (LOGIT_IS_SINGLE_MODE(CONSOLIX_LOGIT_CONSOLE_INDEX)) {
67 LOGIT_STREAM_TRACE_TO(CONSOLIX_LOGIT_CONSOLE_INDEX) << str;
69 logit::LogStream(m_level, m_file, m_line, m_function, CONSOLIX_LOGIT_LOGGER_INDEX) << str;
72# if defined(_WIN32) || defined(_WIN64)
73 handle_ansi_colors_windows(str);
102#if CONSOLIX_USE_LOGIT == 1
103 logit::LogLevel m_level;
106 std::string m_function;
114 if (!message.empty()) {
115 if (message.back() ==
'\n') {
116 std::cout << message;
118 std::cout << message << std::endl;
123# if CONSOLIX_USE_LOGIT == 0 && (defined(_WIN32) || defined(_WIN64))
127 void handle_ansi_colors_windows(
const std::string& message)
const {
128 std::string::size_type start = 0;
129 std::string::size_type pos = 0;
131 HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
133 while ((pos = message.find(
"\033[", start)) != std::string::npos) {
136 std::cout << message.substr(start, pos - start);
140 std::string::size_type end_pos = message.find(
'm', pos);
141 if (end_pos != std::string::npos) {
143 std::string ansi_code = message.substr(pos + 2, end_pos - pos - 2);
144 apply_color_from_ansi_code(ansi_code, handle_stdout);
154 if (start < message.size()) {
155 std::cout << message.substr(start);
157 if (!message.empty()) std::cout << std::endl;
166 void apply_color_from_ansi_code(
const std::string& ansi_code, HANDLE handle_stdout)
const {
168 const int code = std::stoi(ansi_code);
191 SetConsoleTextAttribute(handle_stdout, color_value);