35#if CONSOLIX_USE_LOGIT == 1
38 : m_level(logit::LogLevel::LOG_LVL_TRACE), m_file(__FILE__),
40 m_function(logit::make_relative(__FILE__, LOGIT_BASE_PATH)) {
49 logit::LogLevel level,
50 const std::string& file,
52 const std::string& function)
53 : m_level(level), m_file(file), m_line(line), m_function(function) {
67# if CONSOLIX_USE_LOGIT == 1
68 auto str = utf8_to_cp866(
m_stream.str());
76# if CONSOLIX_USE_LOGIT == 1
77 if (LOGIT_IS_SINGLE_MODE(CONSOLIX_LOGIT_CONSOLE_INDEX)) {
78 LOGIT_STREAM_TRACE_TO(CONSOLIX_LOGIT_CONSOLE_INDEX) << str;
80 logit::LogStream(m_level, m_file, m_line, m_function, CONSOLIX_LOGIT_LOGGER_INDEX) << str;
84 handle_ansi_colors_windows(str);
113#if CONSOLIX_USE_LOGIT == 1
114 logit::LogLevel m_level;
117 std::string m_function;
125 if (!message.empty()) {
126 if (message.back() ==
'\n') {
127 std::cout << message;
129 std::cout << message << std::endl;
134# if CONSOLIX_USE_LOGIT == 0 && defined(_WIN32)
138 void handle_ansi_colors_windows(
const std::string& message)
const {
139 std::string::size_type start = 0;
140 std::string::size_type pos = 0;
142 HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
144 while ((pos = message.find(
"\033[", start)) != std::string::npos) {
147 std::cout << message.substr(start, pos - start);
151 std::string::size_type end_pos = message.find(
'm', pos);
152 if (end_pos != std::string::npos) {
154 std::string ansi_code = message.substr(pos + 2, end_pos - pos - 2);
155 apply_color_from_ansi_code(ansi_code, handle_stdout);
165 if (start < message.size()) {
166 std::cout << message.substr(start);
168 if (!message.empty()) std::cout << std::endl;
177 void apply_color_from_ansi_code(
const std::string& ansi_code, HANDLE handle_stdout)
const {
179 const int code = std::stoi(ansi_code);
202 SetConsoleTextAttribute(handle_stdout, color_value);