mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
fix gcc and clang warnings
This commit is contained in:
parent
a6e2f23780
commit
e66ee8b710
@ -4,26 +4,20 @@ CXX_RELEASE_FLAGS = -O2
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
|
||||
all: example bench
|
||||
debug: example-debug bench-debug
|
||||
all: example
|
||||
debug: example-debug
|
||||
|
||||
example: example.cpp
|
||||
$(CXX) example.cpp -o example-clang $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
bench: bench.cpp
|
||||
$(CXX) bench.cpp -o bench-clang $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
example-debug: example.cpp
|
||||
$(CXX) example.cpp -o example-clang-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS)
|
||||
|
||||
bench-debug: bench.cpp
|
||||
$(CXX) bench.cpp -o bench-clang-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS)
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/*.txt example-clang example-clang-debug bench-clang bench-clang-debug
|
||||
rm -f *.o logs/*.txt example-clang example-clang-debug
|
||||
|
||||
|
||||
rebuild: clean all
|
||||
|
@ -33,25 +33,30 @@ inline void append_int(T n, fmt::memory_buffer &dest)
|
||||
dest.append(i.data(), i.data() + i.size());
|
||||
}
|
||||
|
||||
|
||||
inline void append_and_pad2(int n, fmt::memory_buffer &dest)
|
||||
inline void pad2(int n, fmt::memory_buffer &dest)
|
||||
{
|
||||
if (n > 9)
|
||||
if (n > 99)
|
||||
{
|
||||
append_int(n, dest);
|
||||
return;
|
||||
}
|
||||
if (n > 9) // 10-99
|
||||
{
|
||||
dest.push_back('0' + (n / 10));
|
||||
dest.push_back('0' + (n % 10));
|
||||
return;
|
||||
}
|
||||
if (n >= 0) // 0-9
|
||||
{
|
||||
dest.push_back('0');
|
||||
append_int(n, dest);
|
||||
dest.push_back('0' + n);
|
||||
return;
|
||||
}
|
||||
// negatives (unlikely but just in case, let fmt deal with it)
|
||||
// negatives (unlikely, but just in case, let fmt deal with it)
|
||||
fmt::format_to(dest, "{:02}", n);
|
||||
}
|
||||
|
||||
inline void append_and_pad3(int n, fmt::memory_buffer &dest)
|
||||
inline void pad3(int n, fmt::memory_buffer &dest)
|
||||
{
|
||||
if (n > 99)
|
||||
{
|
||||
@ -61,69 +66,19 @@ inline void append_and_pad3(int n, fmt::memory_buffer &dest)
|
||||
if (n > 9) // 10-99
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0' + n / 10);
|
||||
dest.push_back('0' + n % 10);
|
||||
return;
|
||||
dest.push_back('0' + n / 10);
|
||||
dest.push_back('0' + n % 10);
|
||||
return;
|
||||
}
|
||||
else if (n >= 0)
|
||||
if (n >= 0)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0' + n);
|
||||
return;
|
||||
dest.push_back('0' + n);
|
||||
return;
|
||||
}
|
||||
// negatives (unlikely, but just in case let fmt deal with it)
|
||||
else
|
||||
{
|
||||
fmt::format_to(dest, "{:03}", n);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void append_and_pad6(int n, fmt::memory_buffer &dest)
|
||||
{
|
||||
if (n > 99999)
|
||||
{
|
||||
append_int(n, dest);
|
||||
return;
|
||||
}
|
||||
if (n > 9999)
|
||||
{
|
||||
dest.push_back('0');
|
||||
}
|
||||
else if (n > 999)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
}
|
||||
else if (n > 99)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
}
|
||||
else if (n > 9)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
}
|
||||
else if (n >= 0)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
}
|
||||
else // negatives (unlikely, but just in case let fmt deal with it)
|
||||
{
|
||||
fmt::format_to(dest, "{:06}", n);
|
||||
return;
|
||||
}
|
||||
append_int(n, dest);
|
||||
fmt::format_to(dest, "{:03}", n);
|
||||
}
|
||||
|
||||
} // namespace fmt_helper
|
||||
|
@ -121,11 +121,11 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday); //
|
||||
fmt_helper::append_and_pad2(tm_time.tm_hour, dest);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, dest);
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_sec, dest);
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_int(tm_time.tm_year + 1900, dest);
|
||||
}
|
||||
@ -136,7 +136,7 @@ class C_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_year % 100, dest);
|
||||
fmt_helper::pad2(tm_time.tm_year % 100, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -145,11 +145,11 @@ class D_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mon + 1, dest);
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
|
||||
dest.push_back('/');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mday, dest);
|
||||
fmt_helper::pad2(tm_time.tm_mday, dest);
|
||||
dest.push_back('/');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_year % 100, dest);
|
||||
fmt_helper::pad2(tm_time.tm_year % 100, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -167,7 +167,7 @@ class m_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mon + 1, dest);
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -177,7 +177,7 @@ class d_formatter SPDLOG_FINAL : public flag_formatter
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{:02}", tm_time.tm_mday);
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mday, dest);
|
||||
fmt_helper::pad2(tm_time.tm_mday, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -186,7 +186,7 @@ class H_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_hour, dest);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -195,7 +195,7 @@ class I_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(to12h(tm_time), dest);
|
||||
fmt_helper::pad2(to12h(tm_time), dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -204,7 +204,7 @@ class M_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, dest);
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -213,7 +213,7 @@ class S_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_sec, dest);
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -224,7 +224,7 @@ class e_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
||||
fmt_helper::append_and_pad3(static_cast<int>(millis), dest);
|
||||
fmt_helper::pad3(static_cast<int>(millis), dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -235,7 +235,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration).count() % 1000000;
|
||||
fmt_helper::append_and_pad6(static_cast<int>(micros), dest);
|
||||
fmt::format_to(dest, "{:06}", static_cast<int>(micros));
|
||||
}
|
||||
};
|
||||
|
||||
@ -275,11 +275,11 @@ class r_formatter SPDLOG_FINAL : public flag_formatter
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{:02}:{:02}:{:02} {}", to12h(tm_time), tm_time.tm_min, tm_time.tm_sec, ampm(tm_time));
|
||||
fmt_helper::append_and_pad2(to12h(tm_time), dest);
|
||||
fmt_helper::pad2(to12h(tm_time), dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, dest);
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_sec, dest);
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
fmt::format_to(dest, " {}", ampm(tm_time));
|
||||
}
|
||||
};
|
||||
@ -289,9 +289,9 @@ class R_formatter SPDLOG_FINAL : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_and_pad2(tm_time.tm_hour, dest);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, dest);
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -301,11 +301,11 @@ class T_formatter SPDLOG_FINAL : public flag_formatter
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{:02}:{:02}:{:02}", tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
|
||||
fmt_helper::append_and_pad2(tm_time.tm_hour, dest);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, dest);
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(tm_time.tm_sec, dest);
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -344,9 +344,9 @@ public:
|
||||
int h = total_minutes / 60;
|
||||
int m = total_minutes % 60;
|
||||
dest.push_back(sign);
|
||||
fmt_helper::append_and_pad2(h, dest);
|
||||
fmt_helper::pad2(h, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::append_and_pad2(m, dest);
|
||||
fmt_helper::pad2(m, dest);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -466,24 +466,24 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
|
||||
if (cached_header_.size() == 0 || cached_seconds_ts_ != seconds)
|
||||
{
|
||||
cached_header_ = std::move(fmt::memory_buffer());
|
||||
cached_header_ = fmt::memory_buffer();
|
||||
cached_header_.push_back('[');
|
||||
fmt_helper::append_int(tm_time.tm_year + 1900, cached_header_);
|
||||
cached_header_.push_back('-');
|
||||
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mon + 1, cached_header_);
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, cached_header_);
|
||||
cached_header_.push_back('-');
|
||||
|
||||
fmt_helper::append_and_pad2(tm_time.tm_mday, cached_header_);
|
||||
fmt_helper::pad2(tm_time.tm_mday, cached_header_);
|
||||
cached_header_.push_back(' ');
|
||||
|
||||
fmt_helper::append_and_pad2(tm_time.tm_hour, cached_header_);
|
||||
fmt_helper::pad2(tm_time.tm_hour, cached_header_);
|
||||
cached_header_.push_back(':');
|
||||
|
||||
fmt_helper::append_and_pad2(tm_time.tm_min, cached_header_);
|
||||
fmt_helper::pad2(tm_time.tm_min, cached_header_);
|
||||
cached_header_.push_back(':');
|
||||
|
||||
fmt_helper::append_and_pad2(tm_time.tm_sec, cached_header_);
|
||||
fmt_helper::pad2(tm_time.tm_sec, cached_header_);
|
||||
cached_header_.push_back('.');
|
||||
|
||||
cached_seconds_ts_ = seconds;
|
||||
@ -491,7 +491,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
||||
fmt_helper::append_buf(cached_header_, dest);
|
||||
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
||||
fmt_helper::append_and_pad3(static_cast<int>(millis), dest);
|
||||
fmt_helper::pad3(static_cast<int>(millis), dest);
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
#else // no datetime needed
|
||||
@ -530,7 +530,9 @@ public:
|
||||
std::string eol = spdlog::details::os::default_eol)
|
||||
: eol_(std::move(eol))
|
||||
, pattern_time_(pattern_time)
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
compile_pattern(pattern);
|
||||
}
|
||||
|
||||
@ -557,7 +559,7 @@ public:
|
||||
private:
|
||||
const std::string eol_;
|
||||
const pattern_time_type pattern_time_;
|
||||
std::tm cached_tm_{};
|
||||
std::tm cached_tm_;
|
||||
std::chrono::seconds last_log_secs_;
|
||||
|
||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||
@ -569,6 +571,7 @@ private:
|
||||
}
|
||||
return details::os::gmtime(log_clock::to_time_t(msg.time));
|
||||
}
|
||||
|
||||
void handle_flag(char flag)
|
||||
{
|
||||
switch (flag)
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
void set_pattern(const std::string& pattern)
|
||||
void set_pattern(const std::string &pattern)
|
||||
{
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
|
@ -27,23 +27,27 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
|
||||
#endif
|
||||
} // namespace sinks
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name) {
|
||||
return Factory::template create<sinks::stdout_color_sink_mt>(logger_name);
|
||||
}
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_color_sink_mt>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stdout_color_st(const std::string &logger_name) {
|
||||
return Factory::template create<sinks::stdout_color_sink_st>(logger_name);
|
||||
}
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stdout_color_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_color_sink_st>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name) {
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name);
|
||||
}
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stderr_color_st(const std::string &logger_name) {
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name);
|
||||
}
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> stderr_color_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
Loading…
Reference in New Issue
Block a user