1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-28 03:33:51 +00:00

Compare commits

...

11 Commits

Author SHA1 Message Date
gabime
653ec05c0e Updated .clang-tidy with more checks 2019-11-08 16:42:16 +02:00
gabime
be2a751513 Fixed clang-tidy warning in example 2019-11-08 16:35:18 +02:00
gabime
840adfbbcf Added performance chacks tp .clang-tidy 2019-11-08 16:32:57 +02:00
gabime
3999613eca Added performance chacks tp .clang-tidy 2019-11-08 16:27:08 +02:00
gabime
bff85725d2 Fixed some more clang-tidy warnings 2019-11-08 16:20:41 +02:00
gabime
93008b2369 Fix clang-tidy warning about non existing move 2019-11-08 15:31:33 +02:00
gabime
be336e7514 Added noexcept to log_msg move constructor 2019-11-08 15:21:18 +02:00
gabime
255f7f2dee Optimze backtracer operator= 2019-11-08 15:09:57 +02:00
gabime
de2c07ac62 always cache gmt offset 2019-11-08 14:37:52 +02:00
gabime
844d54d7e6 Fix #1302 2019-11-08 14:27:05 +02:00
gabime
ff3e6c7248 Fix issue #1306 2019-11-08 14:08:31 +02:00
8 changed files with 27 additions and 23 deletions

View File

@ -143,7 +143,7 @@ void async_example()
#include "spdlog/fmt/bin_to_hex.h" #include "spdlog/fmt/bin_to_hex.h"
void binary_example() void binary_example()
{ {
std::vector<char> buf; std::vector<char> buf(80);
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
{ {
buf.push_back(static_cast<char>(i & 0xff)); buf.push_back(static_cast<char>(i & 0xff));

View File

@ -26,7 +26,7 @@ SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other)
{ {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
enabled_ = other.enabled(); enabled_ = other.enabled();
messages_ = other.messages_; messages_ = std::move(other.messages_);
return *this; return *this;
} }

View File

@ -26,8 +26,8 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
update_string_views(); update_string_views();
} }
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT
: log_msg{std::move(other)} : log_msg{other}
, buffer{std::move(other.buffer)} , buffer{std::move(other.buffer)}
{ {
update_string_views(); update_string_views();
@ -42,9 +42,9 @@ SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &ot
return *this; return *this;
} }
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT
{ {
log_msg::operator=(std::move(other)); log_msg::operator=(other);
buffer = std::move(other.buffer); buffer = std::move(other.buffer);
update_string_views(); update_string_views();
return *this; return *this;

View File

@ -20,9 +20,9 @@ public:
log_msg_buffer() = default; log_msg_buffer() = default;
explicit log_msg_buffer(const log_msg &orig_msg); explicit log_msg_buffer(const log_msg &orig_msg);
log_msg_buffer(const log_msg_buffer &other); log_msg_buffer(const log_msg_buffer &other);
log_msg_buffer(log_msg_buffer &&other); log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT;
log_msg_buffer &operator=(const log_msg_buffer &other); log_msg_buffer &operator=(const log_msg_buffer &other);
log_msg_buffer &operator=(log_msg_buffer &&other); log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT;
}; };
} // namespace details } // namespace details

View File

@ -277,7 +277,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
return offset; return offset;
#else #else
#if defined(sun) || defined(__sun) || defined(_AIX) #if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
struct helper struct helper
{ {
@ -428,7 +428,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
{ {
if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max())) if (wstr.size() > static_cast<size_t>((std::numeric_limits<int>::max())))
{ {
SPDLOG_THROW(spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8")); SPDLOG_THROW(spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8"));
} }

View File

@ -593,14 +593,7 @@ public:
const size_t field_size = 6; const size_t field_size = 6;
ScopedPadder p(field_size, padinfo_, dest); ScopedPadder p(field_size, padinfo_, dest);
#ifdef _WIN32 auto total_minutes = get_cached_offset(msg, tm_time);
int total_minutes = get_cached_offset(msg, tm_time);
#else
// No need to cache under gcc,
// it is very fast (already stored in tm.tm_gmtoff)
(void)(msg);
int total_minutes = os::utc_minutes_offset(tm_time);
#endif
bool is_negative = total_minutes < 0; bool is_negative = total_minutes < 0;
if (is_negative) if (is_negative)
{ {
@ -619,7 +612,6 @@ public:
private: private:
log_clock::time_point last_update_{std::chrono::seconds(0)}; log_clock::time_point last_update_{std::chrono::seconds(0)};
#ifdef _WIN32
int offset_minutes_{0}; int offset_minutes_{0};
int get_cached_offset(const log_msg &msg, const std::tm &tm_time) int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
@ -632,7 +624,6 @@ private:
} }
return offset_minutes_; return offset_minutes_;
} }
#endif
}; };
// Thread id // Thread id
@ -885,7 +876,7 @@ public:
fmt_helper::pad6(static_cast<size_t>(delta_units.count()), dest); fmt_helper::pad6(static_cast<size_t>(delta_units.count()), dest);
} }
protected: private:
log_clock::time_point last_message_time_; log_clock::time_point last_message_time_;
}; };

View File

@ -150,7 +150,7 @@ SPDLOG_INLINE std::vector<sink_ptr> &logger::sinks()
// error handler // error handler
SPDLOG_INLINE void logger::set_error_handler(err_handler handler) SPDLOG_INLINE void logger::set_error_handler(err_handler handler)
{ {
custom_err_handler_ = handler; custom_err_handler_ = std::move(handler);
} }
// create new logger with same sinks and configuration. // create new logger with same sinks and configuration.

View File

@ -1,4 +1,17 @@
Checks: 'modernize-*,modernize-use-override,google-*,-google-runtime-references,misc-*,clang-analyzer-*,-misc-non-private-member-variables-in-classes, -modernize-use-trailing-return-type' Checks: '\
cppcoreguidelines-*,\
performance-*,\
-performance-unnecessary-value-param,\
modernize-*,\
-modernize-use-trailing-return-type,\
google-*,\
-google-runtime-references,\
misc-*,\
-misc-non-private-member-variables-in-classes,\
cert-*,\
readability-*,\
clang-analyzer-*'
WarningsAsErrors: '' WarningsAsErrors: ''
HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h' HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h'
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false