2#ifndef _LOGIT_SIMPLE_LOG_FORMATTER_HPP_INCLUDED
3#define _LOGIT_SIMPLE_LOG_FORMATTER_HPP_INCLUDED
10#include <time_shield/time_conversions.hpp>
24 std::string
pattern =
"[%Y-%m-%d %H:%M:%S.%e] [%ffn:%#] [%!] [thread:%t] [%l] %^%v%$";
47 void set_pattern(
const std::string& pattern,
bool json_format =
false) {
100 std::ostringstream oss;
102 instruction.apply(oss, record, dt);
114 std::ostringstream oss;
116 <<
"\"log_level\": " <<
static_cast<int>(record.
log_level) <<
", "
119 <<
"\"line\": " << record.
line <<
", "
123 <<
"\"args_array\": [";
125 for (
size_t i = 0; i < record.
args_array.size(); ++i) {
126 if (i > 0) oss <<
", ";
145 std::ostringstream oss;
146 for (
char c : input) {
148 case '"': oss <<
"\\\"";
break;
149 case '\\': oss <<
"\\\\";
break;
150 case '\b': oss <<
"\\b";
break;
151 case '\f': oss <<
"\\f";
break;
152 case '\n': oss <<
"\\n";
break;
153 case '\r': oss <<
"\\r";
break;
154 case '\t': oss <<
"\\t";
break;
156 if (
'\x00' <= c && c <=
'\x1f') {
158 << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(c);
174 std::ostringstream oss;
Header file for the pattern compiler used in log formatting.
static std::vector< FormatInstruction > compile(const std::string &pattern, CompileContext context=CompileContext::Default)
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.