mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 02:19:35 +08:00
Removed default_formatter and formatters namespace
This commit is contained in:
@@ -16,52 +16,10 @@
|
||||
|
||||
namespace c11log
|
||||
{
|
||||
namespace formatters
|
||||
{
|
||||
|
||||
class formatter
|
||||
{
|
||||
public:
|
||||
virtual void format(details::log_msg& msg) = 0;
|
||||
};
|
||||
|
||||
|
||||
class default_formatter: public formatter
|
||||
{
|
||||
public:
|
||||
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
|
||||
void format(details::log_msg& msg) override
|
||||
{
|
||||
details::fast_oss oss;
|
||||
_format_time(msg, oss);
|
||||
|
||||
if(!msg.logger_name.empty())
|
||||
oss << " [" << msg.logger_name << ':' << c11log::level::to_str(msg.level) << "] ";
|
||||
else
|
||||
oss << " [" << c11log::level::to_str(msg.level) << "] ";
|
||||
|
||||
oss << msg.raw << details::os::eol();
|
||||
msg.formatted = oss.str();
|
||||
}
|
||||
private:
|
||||
void _format_time(const details::log_msg& msg, std::ostream &output);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace formatter
|
||||
} //namespace c11log
|
||||
|
||||
// Format datetime like this: [2014-03-14 17:15:22]
|
||||
inline void c11log::formatters::default_formatter::_format_time(const details::log_msg& msg, std::ostream &output)
|
||||
{
|
||||
output.fill('0');
|
||||
output << '[' << msg.tm_time.tm_year + 1900 << '-';
|
||||
output.width(2);
|
||||
output << msg.tm_time.tm_mon + 1 << '-';
|
||||
output << msg.tm_time.tm_mday << ' ';
|
||||
output << msg.tm_time.tm_hour << ':';
|
||||
output << msg.tm_time.tm_min << ':';
|
||||
output << msg.tm_time.tm_sec << ']';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user