18#include <kcenon/common/interfaces/logger_interface.h>
23using log_level = common::interfaces::log_level;
44 case log_level::critical:
return "CRITICAL";
45 case log_level::error:
return "ERROR";
46 case log_level::warning:
return "WARNING";
47 case log_level::info:
return "INFO";
48 case log_level::debug:
return "DEBUG";
49 case log_level::trace:
return "TRACE";
50 case log_level::off:
return "OFF";
78 case log_level::critical:
return "\033[1;35m";
79 case log_level::error:
return "\033[1;31m";
80 case log_level::warning:
return "\033[1;33m";
81 case log_level::info:
return "\033[1;32m";
82 case log_level::debug:
return "\033[1;36m";
83 case log_level::trace:
return "\033[37m";
84 case log_level::off:
return "\033[90m";
115 std::ostringstream oss;
118 case '"': oss <<
"\\\"";
break;
119 case '\\': oss <<
"\\\\";
break;
120 case '/': oss <<
"\\/";
break;
121 case '\b': oss <<
"\\b";
break;
122 case '\f': oss <<
"\\f";
break;
123 case '\n': oss <<
"\\n";
break;
124 case '\r': oss <<
"\\r";
break;
125 case '\t': oss <<
"\\t";
break;
128 if (c >= 0 && c < 0x20) {
130 << std::hex << std::setw(4) << std::setfill(
'0')
131 <<
static_cast<int>(c);
156 std::ostringstream oss;
159 case '&': oss <<
"&";
break;
160 case '<': oss <<
"<";
break;
161 case '>': oss <<
">";
break;
162 case '"': oss <<
""";
break;
163 case '\'': oss <<
"'";
break;
164 default: oss << c;
break;
184 if (file_path.empty()) {
188 size_t pos = file_path.find_last_of(
"/\\");
189 if (pos != std::string::npos) {
190 return file_path.substr(pos + 1);
204 static std::string
trim(
const std::string& str) {
205 const char* whitespace =
" \t\n\r\f\v";
207 size_t start = str.find_first_not_of(whitespace);
208 if (start == std::string::npos) {
212 size_t end = str.find_last_not_of(whitespace);
213 return str.substr(start, end - start + 1);
224 static std::string
to_lower(
const std::string& str) {
227 if (c >=
'A' && c <=
'Z') {
242 static std::string
to_upper(
const std::string& str) {
245 if (c >=
'a' && c <=
'z') {
263 const std::string& str,
264 const std::string& from,
265 const std::string& to
274 while ((pos =
result.find(from, pos)) != std::string::npos) {
275 result.replace(pos, from.length(), to);
String utility functions for log formatting and conversion.
static std::string level_to_color(log_level level, bool use_colors=true)
Convert log level to ANSI color code.
static std::string level_to_string(log_level level)
Convert log level to human-readable string.
static const char * color_reset()
ANSI color reset sequence.
static std::string escape_json(const std::string &str)
Escape special characters for JSON.
static std::string trim(const std::string &str)
Trim whitespace from both ends of string.
static std::string replace_all(const std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a substring.
static std::string to_upper(const std::string &str)
Convert string to uppercase.
static std::string to_lower(const std::string &str)
Convert string to lowercase.
static std::string escape_xml(const std::string &str)
Escape special characters for XML.
static std::string extract_filename(const std::string &file_path)
Extract filename from full file path.
common::interfaces::log_level log_level