|
|
|
@ -21,288 +21,288 @@
|
|
|
|
|
|
|
|
|
|
namespace spdlog
|
|
|
|
|
{
|
|
|
|
|
namespace details
|
|
|
|
|
{
|
|
|
|
|
class flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
namespace details
|
|
|
|
|
{
|
|
|
|
|
class flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~flag_formatter()
|
|
|
|
|
{}
|
|
|
|
|
virtual void format(details::log_msg& msg, const std::tm& tm_time) = 0;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
// name & level pattern appenders
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
class name_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
// name & level pattern appenders
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
class name_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << *msg.logger_name;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// log level appender
|
|
|
|
|
class level_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// log level appender
|
|
|
|
|
class level_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << level::to_str(msg.level);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// short log level appender
|
|
|
|
|
class short_level_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// short log level appender
|
|
|
|
|
class short_level_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << level::to_short_str(msg.level);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Date time pattern appenders
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Date time pattern appenders
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static const char* ampm(const tm& t)
|
|
|
|
|
{
|
|
|
|
|
static const char* ampm(const tm& t)
|
|
|
|
|
{
|
|
|
|
|
return t.tm_hour >= 12 ? "PM" : "AM";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int to12h(const tm& t)
|
|
|
|
|
{
|
|
|
|
|
static int to12h(const tm& t)
|
|
|
|
|
{
|
|
|
|
|
return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Abbreviated weekday name
|
|
|
|
|
static const std::string days[]{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
|
|
|
class a_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Abbreviated weekday name
|
|
|
|
|
static const std::string days[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
|
|
|
class a_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << days[tm_time.tm_wday];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Full weekday name
|
|
|
|
|
static const std::string full_days[]{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
|
|
|
|
|
class A_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Full weekday name
|
|
|
|
|
static const std::string full_days[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
|
|
|
|
|
class A_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << full_days[tm_time.tm_wday];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Abbreviated month
|
|
|
|
|
static const std::string months[]{ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };
|
|
|
|
|
class b_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Abbreviated month
|
|
|
|
|
static const std::string months[] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };
|
|
|
|
|
class b_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << months[tm_time.tm_mon];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Full month name
|
|
|
|
|
static const std::string full_months[]{ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
|
|
|
|
|
class B_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Full month name
|
|
|
|
|
static const std::string full_months[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
|
|
|
|
|
class B_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << full_months[tm_time.tm_mon];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//write 2 ints seperated by sep with padding of 2
|
|
|
|
|
static fmt::MemoryWriter& pad_n_join(fmt::MemoryWriter& w, int v1, int v2, char sep)
|
|
|
|
|
{
|
|
|
|
|
//write 2 ints seperated by sep with padding of 2
|
|
|
|
|
static fmt::MemoryWriter& pad_n_join(fmt::MemoryWriter& w, int v1, int v2, char sep)
|
|
|
|
|
{
|
|
|
|
|
w << fmt::pad(v1, 2, '0') << sep << fmt::pad(v2, 2, '0');
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//write 3 ints seperated by sep with padding of 2
|
|
|
|
|
static fmt::MemoryWriter& pad_n_join(fmt::MemoryWriter& w, int v1, int v2, int v3, char sep)
|
|
|
|
|
{
|
|
|
|
|
//write 3 ints seperated by sep with padding of 2
|
|
|
|
|
static fmt::MemoryWriter& pad_n_join(fmt::MemoryWriter& w, int v1, int v2, int v3, char sep)
|
|
|
|
|
{
|
|
|
|
|
w << fmt::pad(v1, 2, '0') << sep << fmt::pad(v2, 2, '0') << sep << fmt::pad(v3, 2, '0');
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Date and time representation (Thu Aug 23 15:35:46 2014)
|
|
|
|
|
class c_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Date and time representation (Thu Aug 23 15:35:46 2014)
|
|
|
|
|
class c_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << days[tm_time.tm_wday] << ' ' << months[tm_time.tm_mon] << ' ' << tm_time.tm_mday << ' ';
|
|
|
|
|
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, ':') << ' ' << tm_time.tm_year + 1900;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// year - 2 digit
|
|
|
|
|
class C_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// year - 2 digit
|
|
|
|
|
class C_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_year % 100, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
|
|
|
|
|
class D_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
|
|
|
|
|
class D_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
pad_n_join(msg.formatted, tm_time.tm_mon + 1, tm_time.tm_mday, tm_time.tm_year % 100, '/');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// year - 4 digit
|
|
|
|
|
class Y_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// year - 4 digit
|
|
|
|
|
class Y_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << tm_time.tm_year + 1900;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// month 1-12
|
|
|
|
|
class m_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// month 1-12
|
|
|
|
|
class m_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_mon + 1, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// day of month 1-31
|
|
|
|
|
class d_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// day of month 1-31
|
|
|
|
|
class d_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_mday, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// hours in 24 format 0-23
|
|
|
|
|
class H_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// hours in 24 format 0-23
|
|
|
|
|
class H_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_hour, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// hours in 12 format 1-12
|
|
|
|
|
class I_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// hours in 12 format 1-12
|
|
|
|
|
class I_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(to12h(tm_time), 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// minutes 0-59
|
|
|
|
|
class M_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// minutes 0-59
|
|
|
|
|
class M_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_min, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// seconds 0-59
|
|
|
|
|
class S_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// seconds 0-59
|
|
|
|
|
class S_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::pad(tm_time.tm_sec, 2, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// milliseconds
|
|
|
|
|
class e_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// milliseconds
|
|
|
|
|
class e_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
auto duration = msg.time.time_since_epoch();
|
|
|
|
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
|
|
|
|
msg.formatted << fmt::pad(static_cast<int>(millis), 3, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// microseconds
|
|
|
|
|
class f_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// microseconds
|
|
|
|
|
class f_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
auto duration = msg.time.time_since_epoch();
|
|
|
|
|
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration).count() % 1000000;
|
|
|
|
|
msg.formatted << fmt::pad(static_cast<int>(micros), 6, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// nanoseconds
|
|
|
|
|
class F_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// nanoseconds
|
|
|
|
|
class F_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
auto duration = msg.time.time_since_epoch();
|
|
|
|
|
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count() % 1000000000;
|
|
|
|
|
msg.formatted << fmt::pad(static_cast<int>(ns), 9, '0');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// AM/PM
|
|
|
|
|
class p_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// AM/PM
|
|
|
|
|
class p_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << ampm(tm_time);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 12 hour clock 02:55:02 pm
|
|
|
|
|
class r_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// 12 hour clock 02:55:02 pm
|
|
|
|
|
class r_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
pad_n_join(msg.formatted, to12h(tm_time), tm_time.tm_min, tm_time.tm_sec, ':') << ' ' << ampm(tm_time);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 24-hour HH:MM time, equivalent to %H:%M
|
|
|
|
|
class R_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// 24-hour HH:MM time, equivalent to %H:%M
|
|
|
|
|
class R_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, ':');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
|
|
|
|
|
class T_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
|
|
|
|
|
class T_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, ':');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ISO 8601 offset from UTC in timezone (+-HH:MM)
|
|
|
|
|
class z_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// ISO 8601 offset from UTC in timezone (+-HH:MM)
|
|
|
|
|
class z_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
|
|
|
|
|
|
|
|
|
|
z_formatter():_last_update(std::chrono::seconds(0))
|
|
|
|
@ -328,7 +328,7 @@ namespace spdlog
|
|
|
|
|
}
|
|
|
|
|
pad_n_join(msg.formatted, h, m, ':');
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
private:
|
|
|
|
|
log_clock::time_point _last_update;
|
|
|
|
|
int _offset_minutes;
|
|
|
|
|
std::mutex _mutex;
|
|
|
|
@ -337,52 +337,53 @@ namespace spdlog
|
|
|
|
|
{
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
std::lock_guard<std::mutex> l(_mutex);
|
|
|
|
|
if (msg.time - _last_update >= cache_refresh) {
|
|
|
|
|
if (msg.time - _last_update >= cache_refresh)
|
|
|
|
|
{
|
|
|
|
|
_offset_minutes = os::utc_minutes_offset(tm_time);
|
|
|
|
|
_last_update = msg.time;
|
|
|
|
|
}
|
|
|
|
|
return _offset_minutes;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Thread id
|
|
|
|
|
class t_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
//Thread id
|
|
|
|
|
class t_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << msg.thread_id;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class v_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
class v_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << fmt::StringRef(msg.raw.data(), msg.raw.size());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ch_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
class ch_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ch_formatter(char ch): _ch(ch)
|
|
|
|
|
{}
|
|
|
|
|
void format(details::log_msg& msg, const std::tm&) override
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << _ch;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
private:
|
|
|
|
|
char _ch;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//aggregate user chars to display as is
|
|
|
|
|
class aggregate_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
//aggregate user chars to display as is
|
|
|
|
|
class aggregate_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
aggregate_formatter()
|
|
|
|
|
{}
|
|
|
|
|
void add_ch(char ch)
|
|
|
|
@ -393,14 +394,14 @@ namespace spdlog
|
|
|
|
|
{
|
|
|
|
|
msg.formatted << _str;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
private:
|
|
|
|
|
std::string _str;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Full info formatter
|
|
|
|
|
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
|
|
|
|
class full_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
// Full info formatter
|
|
|
|
|
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
|
|
|
|
class full_formatter:public flag_formatter
|
|
|
|
|
{
|
|
|
|
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
|
|
|
|
{
|
|
|
|
|
#ifndef SPDLOG_NO_DATETIME
|
|
|
|
@ -442,9 +443,9 @@ namespace spdlog
|
|
|
|
|
msg.formatted << '[' << level::to_str(msg.level) << "] ";
|
|
|
|
|
msg.formatted << fmt::StringRef(msg.raw.data(), msg.raw.size());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// pattern_formatter inline impl
|
|
|
|
@ -458,8 +459,10 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string& patter
|
|
|
|
|
{
|
|
|
|
|
auto end = pattern.end();
|
|
|
|
|
std::unique_ptr<details::aggregate_formatter> user_chars;
|
|
|
|
|
for (auto it = pattern.begin(); it != end; ++it) {
|
|
|
|
|
if (*it == '%') {
|
|
|
|
|
for (auto it = pattern.begin(); it != end; ++it)
|
|
|
|
|
{
|
|
|
|
|
if (*it == '%')
|
|
|
|
|
{
|
|
|
|
|
if (user_chars) //append user chars found so far
|
|
|
|
|
_formatters.push_back(std::move(user_chars));
|
|
|
|
|
|
|
|
|
@ -483,7 +486,8 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string& patter
|
|
|
|
|
}
|
|
|
|
|
inline void spdlog::pattern_formatter::handle_flag(char flag)
|
|
|
|
|
{
|
|
|
|
|
switch (flag) {
|
|
|
|
|
switch (flag)
|
|
|
|
|
{
|
|
|
|
|
// logger name
|
|
|
|
|
case 'n':
|
|
|
|
|
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::name_formatter()));
|
|
|
|
@ -615,7 +619,8 @@ inline void spdlog::pattern_formatter::format(details::log_msg& msg)
|
|
|
|
|
#else
|
|
|
|
|
std::tm tm_time;
|
|
|
|
|
#endif
|
|
|
|
|
for (auto &f : _formatters) {
|
|
|
|
|
for (auto &f : _formatters)
|
|
|
|
|
{
|
|
|
|
|
f->format(msg, tm_time);
|
|
|
|
|
}
|
|
|
|
|
//write eol
|
|
|
|
|