use if statement instead of switch (changes of adding new time specifications outside of standard are probably unlikely anyhow)

pattern_time -> pattern_time_type
ptime variable name -> pattern_time variable name
make sure four spaces used, not tabs
This commit is contained in:
ThePhD
2017-05-31 12:52:12 -04:00
parent 18a0455b91
commit d98d54896b
7 changed files with 28 additions and 43 deletions

View File

@@ -76,9 +76,9 @@ inline void spdlog::async_logger::_set_formatter(spdlog::formatter_ptr msg_forma
_async_log_helper->set_formatter(_formatter);
}
inline void spdlog::async_logger::_set_pattern(const std::string& pattern, pattern_time ptime)
inline void spdlog::async_logger::_set_pattern(const std::string& pattern, pattern_time_type pattern_time)
{
_formatter = std::make_shared<pattern_formatter>(pattern, ptime);
_formatter = std::make_shared<pattern_formatter>(pattern, pattern_time);
_async_log_helper->set_formatter(_formatter);
}

View File

@@ -53,9 +53,9 @@ inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter)
_set_formatter(msg_formatter);
}
inline void spdlog::logger::set_pattern(const std::string& pattern, pattern_time ptime)
inline void spdlog::logger::set_pattern(const std::string& pattern, pattern_time_type pattern_time)
{
_set_pattern(pattern, ptime);
_set_pattern(pattern, pattern_time);
}
@@ -316,9 +316,9 @@ inline void spdlog::logger::_sink_it(details::log_msg& msg)
flush();
}
inline void spdlog::logger::_set_pattern(const std::string& pattern, pattern_time ptime)
inline void spdlog::logger::_set_pattern(const std::string& pattern, pattern_time_type pattern_time)
{
_formatter = std::make_shared<pattern_formatter>(pattern, ptime);
_formatter = std::make_shared<pattern_formatter>(pattern, pattern_time);
}
inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
{

View File

@@ -311,15 +311,7 @@ class R_formatter SPDLOG_FINAL:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << (tm_time.tm_year + 1900);
msg.formatted << '-';
msg.formatted << tm_time.tm_mon;
msg.formatted << '-';
msg.formatted << tm_time.tm_mday;
msg.formatted << ' ';
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, ':');
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, ':');
}
};
@@ -502,13 +494,13 @@ class full_formatter SPDLOG_FINAL:public flag_formatter
///////////////////////////////////////////////////////////////////////////////
// pattern_formatter inline impl
///////////////////////////////////////////////////////////////////////////////
inline spdlog::pattern_formatter::pattern_formatter(const std::string& pattern, pattern_time ptime)
: _time(ptime)
inline spdlog::pattern_formatter::pattern_formatter(const std::string& pattern, pattern_time_type pattern_time)
: _pattern_time(pattern_time)
{
compile_pattern(pattern, _time);
compile_pattern(pattern);
}
inline void spdlog::pattern_formatter::compile_pattern(const std::string& pattern, pattern_time ptime)
inline void spdlog::pattern_formatter::compile_pattern(const std::string& pattern)
{
auto end = pattern.end();
std::unique_ptr<details::aggregate_formatter> user_chars;
@@ -673,26 +665,18 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
}
}
inline std::tm spdlog::pattern_formatter::get_time(details::log_msg& msg) {
if (_pattern_time == pattern_time_type::local)
return details::os::localtime(log_clock::to_time_t(msg.time));
else
return details::os::gmtime(log_clock::to_time_t(msg.time));
}
inline void spdlog::pattern_formatter::format(details::log_msg& msg)
{
#ifndef SPDLOG_NO_DATETIME
auto tm_time = [this, &msg]()
{
switch (_time)
{
// it is always faster to put the most-common/default case first
case (pattern_time::local):
return details::os::localtime(log_clock::to_time_t(msg.time));
case (pattern_time::utc):
return details::os::gmtime(log_clock::to_time_t(msg.time));
default:
return details::os::localtime(log_clock::to_time_t(msg.time));
}
}();
auto tm_time = get_time(msg);
#else
std::tm tm_time;
#endif