mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
Add coverity scan to CI and fix warnings (#3400)
* Move callback function in thread_pool ctor * Added const qualifiers to logger.h * Remove unused includes from file_helper-inl.h * Fix comments and remove unused include from helpers-inl.h * Fix typo in comment for set_default_logger method. * Use `std::move` for `old_logger` in `set_default_logger`. * Use std::move in example * Wrap `main` content in try block for exception safety. * Added coverity to ci
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <spdlog/details/os.h>
|
||||
#include <spdlog/details/registry.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
@@ -36,7 +35,7 @@ inline std::string &trim_(std::string &str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// return (name,value) trimmed pair from given "name=value" string.
|
||||
// return (name,value) trimmed pair from the given "name = value" string.
|
||||
// return empty string on missing parts
|
||||
// "key=val" => ("key", "val")
|
||||
// " key = val " => ("key", "val")
|
||||
@@ -55,7 +54,7 @@ inline std::pair<std::string, std::string> extract_kv_(char sep, const std::stri
|
||||
return std::make_pair(trim_(k), trim_(v));
|
||||
}
|
||||
|
||||
// return vector of key/value pairs from sequence of "K1=V1,K2=V2,.."
|
||||
// return vector of key/value pairs from a sequence of "K1=V1,K2=V2,.."
|
||||
// "a=AAA,b=BBB,c=CCC,.." => {("a","AAA"),("b","BBB"),("c", "CCC"),...}
|
||||
inline std::unordered_map<std::string, std::string> extract_key_vals_(const std::string &str) {
|
||||
std::string token;
|
||||
@@ -82,14 +81,14 @@ SPDLOG_INLINE void load_levels(const std::string &input) {
|
||||
bool global_level_found = false;
|
||||
|
||||
for (auto &name_level : key_vals) {
|
||||
auto &logger_name = name_level.first;
|
||||
auto level_name = to_lower_(name_level.second);
|
||||
const auto &logger_name = name_level.first;
|
||||
const auto &level_name = to_lower_(name_level.second);
|
||||
auto level = level::from_str(level_name);
|
||||
// ignore unrecognized level names
|
||||
if (level == level::off && level_name != "off") {
|
||||
continue;
|
||||
}
|
||||
if (logger_name.empty()) // no logger name indicate global level
|
||||
if (logger_name.empty()) // no logger name indicates global level
|
||||
{
|
||||
global_level_found = true;
|
||||
global_level = level;
|
||||
|
@@ -11,10 +11,8 @@
|
||||
#include <spdlog/details/os.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
namespace spdlog {
|
||||
|
@@ -101,7 +101,7 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger() {
|
||||
SPDLOG_INLINE logger *registry::get_default_raw() { return default_logger_.get(); }
|
||||
|
||||
// set default logger.
|
||||
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
|
||||
// the default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
|
||||
SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr<logger> new_default_logger) {
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
if (new_default_logger != nullptr) {
|
||||
|
@@ -35,7 +35,7 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items,
|
||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items,
|
||||
size_t threads_n,
|
||||
std::function<void()> on_thread_start)
|
||||
: thread_pool(q_max_items, threads_n, on_thread_start, [] {}) {}
|
||||
: thread_pool(q_max_items, threads_n, std::move(on_thread_start), [] {}) {}
|
||||
|
||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
: thread_pool(q_max_items, threads_n, [] {}, [] {}) {}
|
||||
@@ -94,8 +94,7 @@ void SPDLOG_INLINE thread_pool::worker_loop_() {
|
||||
}
|
||||
|
||||
// process next message in the queue
|
||||
// return true if this thread should still be active (while no terminate msg
|
||||
// was received)
|
||||
// returns true if this thread should still be active (while no terminated msg was received)
|
||||
bool SPDLOG_INLINE thread_pool::process_next_msg_() {
|
||||
async_msg incoming_async_msg;
|
||||
q_.dequeue(incoming_async_msg);
|
||||
|
@@ -57,7 +57,7 @@ SPDLOG_INLINE void logger::swap(spdlog::logger &other) SPDLOG_NOEXCEPT {
|
||||
std::swap(tracer_, other.tracer_);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void swap(logger &a, logger &b) { a.swap(b); }
|
||||
SPDLOG_INLINE void swap(logger &a, logger &b) noexcept { a.swap(b); }
|
||||
|
||||
SPDLOG_INLINE void logger::set_level(level::level_enum log_level) { level_.store(log_level); }
|
||||
|
||||
@@ -163,12 +163,12 @@ SPDLOG_INLINE void logger::dump_backtrace_() {
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) {
|
||||
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) const {
|
||||
auto flush_level = flush_level_.load(std::memory_order_relaxed);
|
||||
return (msg.level >= flush_level) && (msg.level != level::off);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg) {
|
||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg) const {
|
||||
if (custom_err_handler_) {
|
||||
custom_err_handler_(msg);
|
||||
} else {
|
||||
|
@@ -363,14 +363,14 @@ protected:
|
||||
virtual void sink_it_(const details::log_msg &msg);
|
||||
virtual void flush_();
|
||||
void dump_backtrace_();
|
||||
bool should_flush_(const details::log_msg &msg);
|
||||
bool should_flush_(const details::log_msg &msg) const;
|
||||
|
||||
// handle errors during logging.
|
||||
// default handler prints the error to stderr at max rate of 1 message/sec.
|
||||
void err_handler_(const std::string &msg);
|
||||
void err_handler_(const std::string &msg) const;
|
||||
};
|
||||
|
||||
void swap(logger &a, logger &b);
|
||||
void swap(logger &a, logger &b) noexcept;
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
|
Reference in New Issue
Block a user