mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
Removed default_formatter and formatters namespace
This commit is contained in:
parent
481fdbcbb1
commit
c573d2b7ab
@ -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 << ']';
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "sinks/base_sink.h"
|
||||
#include "common.h"
|
||||
#include "pattern_formatter.h"
|
||||
|
||||
namespace c11log
|
||||
{
|
||||
@ -29,7 +30,7 @@ public:
|
||||
using sink_ptr = std::shared_ptr<sinks::isink>;
|
||||
using sinks_vector_t = std::vector<sink_ptr>;
|
||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||
using formatter_ptr = std::unique_ptr<formatters::formatter>;
|
||||
using formatter_ptr = std::unique_ptr<formatter>;
|
||||
|
||||
logger(const std::string& name, sinks_init_list, formatter_ptr = nullptr);
|
||||
template<class It>
|
||||
@ -112,7 +113,7 @@ inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_lis
|
||||
//Seems that vs2013 doesn't support std::atomic member initialization yet
|
||||
_level = level::INFO;
|
||||
if(!_formatter)
|
||||
_formatter = std::make_unique<formatters::default_formatter>();
|
||||
_formatter = std::make_unique<pattern_formatter>("%t");
|
||||
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ class e_appender :public pattern_appender
|
||||
void append(const details::log_msg& msg, details::fast_oss& oss) override
|
||||
{
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
||||
int millis = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
|
||||
oss.put_int(millis, 3);
|
||||
}
|
||||
};
|
||||
@ -166,8 +166,6 @@ private:
|
||||
}
|
||||
|
||||
|
||||
namespace formatters
|
||||
{
|
||||
class pattern_formatter : public formatter
|
||||
{
|
||||
|
||||
@ -182,16 +180,16 @@ private:
|
||||
void compile_pattern(const std::string& pattern);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
c11log::formatters::pattern_formatter::pattern_formatter(const std::string& pattern)
|
||||
|
||||
inline c11log::pattern_formatter::pattern_formatter(const std::string& pattern)
|
||||
{
|
||||
compile_pattern(pattern);
|
||||
}
|
||||
|
||||
|
||||
void c11log::formatters::pattern_formatter::compile_pattern(const std::string& pattern)
|
||||
inline void c11log::pattern_formatter::compile_pattern(const std::string& pattern)
|
||||
{
|
||||
auto end = pattern.end();
|
||||
for (auto it = pattern.begin(); it != end; ++it)
|
||||
@ -211,7 +209,7 @@ void c11log::formatters::pattern_formatter::compile_pattern(const std::string& p
|
||||
}
|
||||
|
||||
}
|
||||
void c11log::formatters::pattern_formatter::handle_flag(char flag)
|
||||
inline void c11log::pattern_formatter::handle_flag(char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
@ -273,7 +271,7 @@ void c11log::formatters::pattern_formatter::handle_flag(char flag)
|
||||
}
|
||||
|
||||
|
||||
void c11log::formatters::pattern_formatter::format(details::log_msg& msg)
|
||||
inline void c11log::pattern_formatter::format(details::log_msg& msg)
|
||||
{
|
||||
details::fast_oss oss;
|
||||
for (auto &appender : _appenders)
|
||||
|
Loading…
Reference in New Issue
Block a user