2#ifndef _LOGIT_SIMPLE_LOG_FORMATTER_HPP_INCLUDED
3#define _LOGIT_SIMPLE_LOG_FORMATTER_HPP_INCLUDED
22 std::string
pattern =
"[%Y-%m-%d %H:%M:%S.%e] [%ffn:%#] [%!] [thread:%t] [%l] %^%v%$";
45 void set_pattern(
const std::string& pattern,
bool json_format =
false) {
86 auto dt = time_shield::to_date_time_ms<time_shield::DateTimeStruct>(record.
timestamp_ms);
87 std::ostringstream oss;
89 instruction.apply(oss, record, dt);
101 std::ostringstream oss;
103 <<
"\"log_level\": " <<
static_cast<int>(record.
log_level) <<
", "
106 <<
"\"line\": " << record.
line <<
", "
110 <<
"\"args_array\": [";
112 for (
size_t i = 0; i < record.
args_array.size(); ++i) {
113 if (i > 0) oss <<
", ";
132 std::ostringstream oss;
133 for (
char c : input) {
135 case '"': oss <<
"\\\"";
break;
136 case '\\': oss <<
"\\\\";
break;
137 case '\b': oss <<
"\\b";
break;
138 case '\f': oss <<
"\\f";
break;
139 case '\n': oss <<
"\\n";
break;
140 case '\r': oss <<
"\\r";
break;
141 case '\t': oss <<
"\\t";
break;
143 if (
'\x00' <= c && c <=
'\x1f') {
145 << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(c);
161 std::ostringstream oss;
Header file for the pattern compiler used in log formatting.
static std::vector< FormatInstruction > compile(const std::string &pattern)
Compiles a pattern string into a list of format instructions.
The primary namespace for the LogIt++ library.
Stores log metadata and content.
const std::string function
Function name.
const int line
Line number in the source file.
std::thread::id thread_id
ID of the logging thread.
const LogLevel log_level
Log level (severity).
const int64_t timestamp_ms
Timestamp in milliseconds.
const std::string file
Source file name.
const std::string format
Format string for the message.
std::vector< VariableValue > args_array
Argument values for the log.
const std::string arg_names
Argument names for the log.