mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 10:29:02 +08:00
Renamed spdlog::log_level to spdlog::level and added some level tests
This commit is contained in:
@@ -64,7 +64,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
if (sink->should_log(msg.level))
|
||||
if (sink->should_log(msg.log_level))
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
|
@@ -87,8 +87,8 @@ SPDLOG_INLINE void load_levels(const std::string &input)
|
||||
}
|
||||
|
||||
auto key_vals = extract_key_vals_(input);
|
||||
std::unordered_map<std::string, log_level> levels;
|
||||
log_level global_level = log_level::info;
|
||||
std::unordered_map<std::string, level> levels;
|
||||
level global_level = level::info;
|
||||
bool global_level_found = false;
|
||||
|
||||
for (auto &name_level : key_vals)
|
||||
@@ -97,7 +97,7 @@ SPDLOG_INLINE void load_levels(const std::string &input)
|
||||
auto level_name = to_lower_(name_level.second);
|
||||
auto level = level_from_str(level_name);
|
||||
// ignore unrecognized level names
|
||||
if (level == log_level::off && level_name != "off")
|
||||
if (level == level::off && level_name != "off")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -12,22 +12,22 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
SPDLOG_INLINE spdlog::log_level level_from_str(const std::string &name) noexcept
|
||||
SPDLOG_INLINE spdlog::level level_from_str(const std::string &name) noexcept
|
||||
{
|
||||
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
|
||||
if (it != std::end(level_string_views))
|
||||
return static_cast<log_level>(std::distance(std::begin(level_string_views), it));
|
||||
return static_cast<level>(std::distance(std::begin(level_string_views), it));
|
||||
|
||||
// check also for "warn" and "err" before giving up..
|
||||
if (name == "warn")
|
||||
{
|
||||
return spdlog::log_level::warn;
|
||||
return spdlog::level::warn;
|
||||
}
|
||||
if (name == "err")
|
||||
{
|
||||
return log_level::err;
|
||||
return level::err;
|
||||
}
|
||||
return log_level::off;
|
||||
return level::off;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
|
||||
|
@@ -160,7 +160,7 @@ template<typename T>
|
||||
using is_convertible_to_sv = std::enable_if_t<std::is_convertible_v<T, string_view_t>>;
|
||||
|
||||
// Log level enum
|
||||
enum class log_level
|
||||
enum class level
|
||||
{
|
||||
trace = SPDLOG_LEVEL_TRACE,
|
||||
debug = SPDLOG_LEVEL_DEBUG,
|
||||
@@ -173,9 +173,9 @@ enum class log_level
|
||||
};
|
||||
|
||||
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
||||
using atomic_level_t = details::null_atomic<log_level>;
|
||||
using atomic_level_t = details::null_atomic<level>;
|
||||
#else
|
||||
using atomic_level_t = std::atomic<log_level>;
|
||||
using atomic_level_t = std::atomic<level>;
|
||||
#endif
|
||||
|
||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||
@@ -186,25 +186,25 @@ enum class log_level
|
||||
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"}
|
||||
#endif
|
||||
|
||||
constexpr size_t to_size_t(log_level level) noexcept
|
||||
constexpr size_t to_size_t(level lvl) noexcept
|
||||
{
|
||||
return static_cast<size_t>(level);
|
||||
return static_cast<size_t>(lvl);
|
||||
}
|
||||
constexpr auto levels_count = to_size_t(log_level::n_levels);
|
||||
constexpr auto levels_count = to_size_t(level::n_levels);
|
||||
constexpr std::array<string_view_t, levels_count> level_string_views SPDLOG_LEVEL_NAMES;
|
||||
constexpr std::array<const char *, levels_count> short_level_names SPDLOG_SHORT_LEVEL_NAMES;
|
||||
|
||||
constexpr string_view_t to_string_view(spdlog::log_level lvl) noexcept
|
||||
constexpr string_view_t to_string_view(spdlog::level lvl) noexcept
|
||||
{
|
||||
return level_string_views.at(to_size_t(lvl));
|
||||
}
|
||||
|
||||
constexpr const char *to_short_c_str(spdlog::log_level lvl) noexcept
|
||||
constexpr const char *to_short_c_str(spdlog::level lvl) noexcept
|
||||
{
|
||||
return short_level_names.at(to_size_t(lvl));
|
||||
}
|
||||
|
||||
SPDLOG_API spdlog::log_level level_from_str(const std::string &name) noexcept;
|
||||
SPDLOG_API spdlog::level level_from_str(const std::string &name) noexcept;
|
||||
|
||||
|
||||
|
||||
|
@@ -13,9 +13,9 @@ namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name,
|
||||
spdlog::log_level lvl, spdlog::string_view_t msg)
|
||||
spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: logger_name(a_logger_name)
|
||||
, level(lvl)
|
||||
, log_level(lvl)
|
||||
, time(log_time)
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
, thread_id(os::thread_id())
|
||||
@@ -25,11 +25,11 @@ SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::s
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE log_msg::log_msg(
|
||||
spdlog::source_loc loc, string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg)
|
||||
spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: log_msg(os::now(), loc, a_logger_name, lvl, msg)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg)
|
||||
SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg)
|
||||
{}
|
||||
|
||||
|
@@ -11,14 +11,14 @@ namespace details {
|
||||
struct SPDLOG_API log_msg
|
||||
{
|
||||
log_msg() = default;
|
||||
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, log_level lvl, string_view_t msg);
|
||||
log_msg(source_loc loc, string_view_t logger_name, log_level lvl, string_view_t msg);
|
||||
log_msg(string_view_t logger_name, log_level lvl, string_view_t msg);
|
||||
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(const log_msg &other) = default;
|
||||
log_msg &operator=(const log_msg &other) = default;
|
||||
|
||||
string_view_t logger_name;
|
||||
log_level level{log_level::off};
|
||||
level log_level{level::off};
|
||||
log_clock::time_point time;
|
||||
size_t thread_id{0};
|
||||
|
||||
|
@@ -142,24 +142,24 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::set_level(log_level log_level)
|
||||
SPDLOG_INLINE void registry::set_level(level level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->set_level(log_level);
|
||||
l.second->set_level(level);
|
||||
}
|
||||
global_log_level_ = log_level;
|
||||
global_log_level_ = level;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::flush_on(log_level log_level)
|
||||
SPDLOG_INLINE void registry::flush_on(level level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->flush_on(log_level);
|
||||
l.second->flush_on(level);
|
||||
}
|
||||
flush_level_ = log_level;
|
||||
flush_level_ = level;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::set_error_handler(err_handler handler)
|
||||
@@ -235,7 +235,7 @@ SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registrat
|
||||
automatic_registration_ = automatic_registration;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::set_levels(log_levels levels, log_level *global_level)
|
||||
SPDLOG_INLINE void registry::set_levels(log_levels levels, level *global_level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
log_levels_ = std::move(levels);
|
||||
|
@@ -27,7 +27,7 @@ class thread_pool;
|
||||
class SPDLOG_API registry
|
||||
{
|
||||
public:
|
||||
using log_levels = std::unordered_map<std::string, log_level>;
|
||||
using log_levels = std::unordered_map<std::string, level>;
|
||||
registry(const registry &) = delete;
|
||||
registry &operator=(const registry &) = delete;
|
||||
|
||||
@@ -53,9 +53,9 @@ public:
|
||||
// Set global formatter. Each sink in each logger will get a clone of this object
|
||||
void set_formatter(std::unique_ptr<formatter> formatter);
|
||||
|
||||
void set_level(log_level log_level);
|
||||
void set_level(level level);
|
||||
|
||||
void flush_on(log_level log_level);
|
||||
void flush_on(level level);
|
||||
|
||||
template<typename Rep, typename Period>
|
||||
void flush_every(std::chrono::duration<Rep, Period> interval)
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
void set_automatic_registration(bool automatic_registration);
|
||||
|
||||
// set levels for all existing/future loggers. global_level can be null if should not set.
|
||||
void set_levels(log_levels levels, log_level *global_level);
|
||||
void set_levels(log_levels levels, level *global_level);
|
||||
|
||||
static registry &instance();
|
||||
|
||||
@@ -101,8 +101,8 @@ private:
|
||||
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
|
||||
log_levels log_levels_;
|
||||
std::unique_ptr<formatter> formatter_;
|
||||
spdlog::log_level global_log_level_ = log_level::info;
|
||||
log_level flush_level_ = log_level::off;
|
||||
spdlog::level global_log_level_ = level::info;
|
||||
level flush_level_ = level::off;
|
||||
err_handler err_handler_;
|
||||
std::shared_ptr<thread_pool> tp_;
|
||||
std::unique_ptr<periodic_worker> periodic_flusher_;
|
||||
|
@@ -31,14 +31,14 @@ SPDLOG_INLINE logger::logger(logger &&other) noexcept
|
||||
, custom_err_handler_(std::move(other.custom_err_handler_))
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE void logger::set_level(log_level log_level)
|
||||
SPDLOG_INLINE void logger::set_level(level level)
|
||||
{
|
||||
level_.store(log_level);
|
||||
level_.store(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE log_level logger::level() const
|
||||
SPDLOG_INLINE level logger::log_level() const
|
||||
{
|
||||
return static_cast<log_level>(level_.load(std::memory_order_relaxed));
|
||||
return static_cast<level>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE const std::string &logger::name() const
|
||||
@@ -77,14 +77,14 @@ SPDLOG_INLINE void logger::flush()
|
||||
flush_();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::flush_on(log_level log_level)
|
||||
SPDLOG_INLINE void logger::flush_on(level level)
|
||||
{
|
||||
flush_level_.store(log_level);
|
||||
flush_level_.store(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE log_level logger::flush_level() const
|
||||
SPDLOG_INLINE level logger::flush_level() const
|
||||
{
|
||||
return static_cast<log_level>(flush_level_.load(std::memory_order_relaxed));
|
||||
return static_cast<level>(flush_level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
// sinks
|
||||
@@ -127,7 +127,7 @@ SPDLOG_INLINE void logger::flush_()
|
||||
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg)
|
||||
{
|
||||
auto flush_level = flush_level_.load(std::memory_order_relaxed);
|
||||
return (msg.level >= flush_level) && (msg.level != log_level::off);
|
||||
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
|
||||
|
@@ -77,7 +77,7 @@ public:
|
||||
|
||||
// log functions
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, log_level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
void log(source_loc loc, level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(log_level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
void log(level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
|
||||
void log(source_loc loc, log_level lvl, S fmt, Args &&...args)
|
||||
void log(source_loc loc, level lvl, S fmt, Args &&...args)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
}
|
||||
|
||||
// log with no format string, just string message
|
||||
void log(source_loc loc, log_level lvl, string_view_t msg)
|
||||
void log(source_loc loc, level lvl, string_view_t msg)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void log(log_level lvl, string_view_t msg)
|
||||
void log(level lvl, string_view_t msg)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
}
|
||||
|
||||
// support for custom time
|
||||
void log(log_clock::time_point log_time, source_loc loc, log_level lvl, string_view_t msg)
|
||||
void log(log_clock::time_point log_time, source_loc loc, level lvl, string_view_t msg)
|
||||
{
|
||||
if (should_log(lvl))
|
||||
{
|
||||
@@ -133,150 +133,150 @@ public:
|
||||
template<typename... Args>
|
||||
void trace(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::info, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::warn, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::warn, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::err, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// log functions with no format string, just string
|
||||
|
||||
void trace(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::trace, msg);
|
||||
log(loc, level::trace, msg);
|
||||
}
|
||||
|
||||
void debug(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::debug, msg);
|
||||
log(loc, level::debug, msg);
|
||||
}
|
||||
|
||||
void info(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::info, msg);
|
||||
log(loc, level::info, msg);
|
||||
}
|
||||
|
||||
void warn(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::warn, msg);
|
||||
log(loc, level::warn, msg);
|
||||
}
|
||||
|
||||
void error(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::err, msg);
|
||||
log(loc, level::err, msg);
|
||||
}
|
||||
|
||||
void critical(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::critical, msg);
|
||||
log(loc, level::critical, msg);
|
||||
}
|
||||
#else
|
||||
template<typename... Args>
|
||||
void trace(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::trace, fmt, std::forward<Args>(args)...);
|
||||
log(level::trace, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::debug, fmt, std::forward<Args>(args)...);
|
||||
log(level::debug, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::info, fmt, std::forward<Args>(args)...);
|
||||
log(level::info, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::warn, fmt, std::forward<Args>(args)...);
|
||||
log(level::warn, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::err, fmt, std::forward<Args>(args)...);
|
||||
log(level::err, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::critical, fmt, std::forward<Args>(args)...);
|
||||
log(level::critical, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// log functions with no format string, just string
|
||||
void trace(string_view_t msg)
|
||||
{
|
||||
log(log_level::trace, msg);
|
||||
log(level::trace, msg);
|
||||
}
|
||||
|
||||
void debug(string_view_t msg)
|
||||
{
|
||||
log(log_level::debug, msg);
|
||||
log(level::debug, msg);
|
||||
}
|
||||
|
||||
void info(string_view_t msg)
|
||||
{
|
||||
log(log_level::info, msg);
|
||||
log(level::info, msg);
|
||||
}
|
||||
|
||||
inline void warn(string_view_t msg)
|
||||
{
|
||||
log(log_level::warn, msg);
|
||||
log(level::warn, msg);
|
||||
}
|
||||
|
||||
void error(string_view_t msg)
|
||||
{
|
||||
log(log_level::err, msg);
|
||||
log(level::err, msg);
|
||||
}
|
||||
|
||||
void critical(string_view_t msg)
|
||||
{
|
||||
log(log_level::critical, msg);
|
||||
log(level::critical, msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
// return true if logging is enabled for the given level.
|
||||
[[nodiscard]] bool should_log(log_level msg_level) const
|
||||
[[nodiscard]] bool should_log(level msg_level) const
|
||||
{
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// set the level of logging
|
||||
void set_level(log_level log_level);
|
||||
void set_level(level level);
|
||||
|
||||
// return the active log level
|
||||
[[nodiscard]] log_level level() const;
|
||||
[[nodiscard]] level log_level() const;
|
||||
|
||||
// return the name of the logger
|
||||
[[nodiscard]] const std::string &name() const;
|
||||
@@ -293,8 +293,8 @@ public:
|
||||
|
||||
// flush functions
|
||||
void flush();
|
||||
void flush_on(log_level log_level);
|
||||
[[nodiscard]] log_level flush_level() const;
|
||||
void flush_on(level level);
|
||||
[[nodiscard]] level flush_level() const;
|
||||
|
||||
// sinks
|
||||
[[nodiscard]] const std::vector<sink_ptr> &sinks() const;
|
||||
@@ -310,13 +310,13 @@ public:
|
||||
protected:
|
||||
std::string name_;
|
||||
std::vector<sink_ptr> sinks_;
|
||||
spdlog::atomic_level_t level_{log_level::info};
|
||||
spdlog::atomic_level_t flush_level_{log_level::off};
|
||||
spdlog::atomic_level_t level_{level::info};
|
||||
spdlog::atomic_level_t flush_level_{level::off};
|
||||
err_handler custom_err_handler_{nullptr};
|
||||
|
||||
// common implementation for after templated public api has been resolved to format string and args
|
||||
template<typename... Args>
|
||||
void log_with_format_(source_loc loc, log_level lvl, string_view_t fmt, Args &&...args)
|
||||
void log_with_format_(source_loc loc, level lvl, string_view_t fmt, Args &&...args)
|
||||
{
|
||||
assert(should_log(lvl));
|
||||
SPDLOG_TRY
|
||||
@@ -336,10 +336,10 @@ protected:
|
||||
// log the given message (if the given log level is high enough)
|
||||
virtual void sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
assert(should_log(msg.level));
|
||||
assert(should_log(msg.log_level));
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
if (sink->should_log(msg.level))
|
||||
if (sink->should_log(msg.log_level))
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
|
@@ -129,7 +129,7 @@ public:
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
const string_view_t &level_name = to_string_view(msg.level);
|
||||
const string_view_t &level_name = to_string_view(msg.log_level);
|
||||
ScopedPadder p(level_name.size(), padinfo_, dest);
|
||||
fmt_helper::append_string_view(level_name, dest);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t level_name{to_short_c_str(msg.level)};
|
||||
string_view_t level_name{to_short_c_str(msg.log_level)};
|
||||
ScopedPadder p(level_name.size(), padinfo_, dest);
|
||||
fmt_helper::append_string_view(level_name, dest);
|
||||
}
|
||||
@@ -991,8 +991,8 @@ public:
|
||||
dest.push_back('[');
|
||||
// wrap the level name with color
|
||||
msg.color_range_start = dest.size();
|
||||
// fmt_helper::append_string_view(log_level::to_c_str(msg.level), dest);
|
||||
fmt_helper::append_string_view(to_string_view(msg.level), dest);
|
||||
// fmt_helper::append_string_view(level::to_c_str(msg.log_level), dest);
|
||||
fmt_helper::append_string_view(to_string_view(msg.log_level), dest);
|
||||
msg.color_range_end = dest.size();
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
|
@@ -41,7 +41,7 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
const android_LogPriority priority = convert_to_android_(msg.level);
|
||||
const android_LogPriority priority = convert_to_android_(msg.log_level);
|
||||
memory_buf_t formatted;
|
||||
if (use_raw_msg_)
|
||||
{
|
||||
@@ -92,21 +92,21 @@ private:
|
||||
return __android_log_buf_write(ID, prio, tag, text);
|
||||
}
|
||||
|
||||
static android_LogPriority convert_to_android_(spdlog::log_level level)
|
||||
static android_LogPriority convert_to_android_(spdlog::level level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case spdlog::log_level::trace:
|
||||
case spdlog::level::trace:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
case spdlog::log_level::debug:
|
||||
case spdlog::level::debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
case spdlog::log_level::info:
|
||||
case spdlog::level::info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case spdlog::log_level::warn:
|
||||
case spdlog::level::warn:
|
||||
return ANDROID_LOG_WARN;
|
||||
case spdlog::log_level::err:
|
||||
case spdlog::level::err:
|
||||
return ANDROID_LOG_ERROR;
|
||||
case spdlog::log_level::critical:
|
||||
case spdlog::level::critical:
|
||||
return ANDROID_LOG_FATAL;
|
||||
default:
|
||||
return ANDROID_LOG_DEFAULT;
|
||||
|
@@ -21,17 +21,17 @@ SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, co
|
||||
|
||||
{
|
||||
set_color_mode(mode);
|
||||
colors_.at(to_size_t(log_level::trace)) = to_string_(white);
|
||||
colors_.at(to_size_t(log_level::debug)) = to_string_(cyan);
|
||||
colors_.at(to_size_t(log_level::info)) = to_string_(green);
|
||||
colors_.at(to_size_t(log_level::warn)) = to_string_(yellow_bold);
|
||||
colors_.at(to_size_t(log_level::err)) = to_string_(red_bold);
|
||||
colors_.at(to_size_t(log_level::critical)) = to_string_(bold_on_red);
|
||||
colors_.at(to_size_t(log_level::off)) = to_string_(reset);
|
||||
colors_.at(to_size_t(level::trace)) = to_string_(white);
|
||||
colors_.at(to_size_t(level::debug)) = to_string_(cyan);
|
||||
colors_.at(to_size_t(level::info)) = to_string_(green);
|
||||
colors_.at(to_size_t(level::warn)) = to_string_(yellow_bold);
|
||||
colors_.at(to_size_t(level::err)) = to_string_(red_bold);
|
||||
colors_.at(to_size_t(level::critical)) = to_string_(bold_on_red);
|
||||
colors_.at(to_size_t(level::off)) = to_string_(reset);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color(log_level color_level, string_view_t color)
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color(level color_level, string_view_t color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_.at(to_size_t(color_level)) = to_string_(color);
|
||||
@@ -52,7 +52,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg
|
||||
// before color range
|
||||
print_range_(formatted, 0, msg.color_range_start);
|
||||
// in color range
|
||||
print_ccode_(colors_.at(static_cast<size_t>(msg.level)));
|
||||
print_ccode_(colors_.at(static_cast<size_t>(msg.log_level)));
|
||||
print_range_(formatted, msg.color_range_start, msg.color_range_end);
|
||||
print_ccode_(reset);
|
||||
// after color range
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
ansicolor_sink &operator=(const ansicolor_sink &other) = delete;
|
||||
ansicolor_sink &operator=(ansicolor_sink &&other) = delete;
|
||||
|
||||
void set_color(log_level color_level, string_view_t color);
|
||||
void set_color(level color_level, string_view_t color);
|
||||
void set_color_mode(color_mode mode);
|
||||
bool should_color();
|
||||
|
||||
|
@@ -59,7 +59,7 @@ protected:
|
||||
{
|
||||
for (auto &sub_sink : sinks_)
|
||||
{
|
||||
if (sub_sink->should_log(msg.level))
|
||||
if (sub_sink->should_log(msg.log_level))
|
||||
{
|
||||
sub_sink->log(msg);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@
|
||||
// #include <spdlog/sinks/dup_filter_sink.h>
|
||||
//
|
||||
// int main() {
|
||||
// auto dup_filter = std::make_shared<dup_filter_sink_st>(std::chrono::seconds(5), log_level::info);
|
||||
// auto dup_filter = std::make_shared<dup_filter_sink_st>(std::chrono::seconds(5), level::info);
|
||||
// dup_filter->add_sink(std::make_shared<stdout_color_sink_mt>());
|
||||
// spdlog::logger l("logger", dup_filter);
|
||||
// l.info("Hello");
|
||||
@@ -41,7 +41,7 @@ class dup_filter_sink : public dist_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
template<class Rep, class Period>
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, log_level notification_level = log_level::info)
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, level notification_level = level::info)
|
||||
: max_skip_duration_{max_skip_duration}
|
||||
, log_level_{notification_level}
|
||||
{}
|
||||
@@ -51,7 +51,7 @@ protected:
|
||||
log_clock::time_point last_msg_time_;
|
||||
std::string last_msg_payload_;
|
||||
size_t skip_counter_ = 0;
|
||||
log_level log_level_;
|
||||
level log_level_;
|
||||
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
|
@@ -66,8 +66,8 @@ protected:
|
||||
|
||||
if (client_ != nullptr)
|
||||
{
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << log_level::to_string_view(msg.level).data()
|
||||
<< "level_num" << msg.level << "message" << std::string(msg.payload.begin(), msg.payload.end())
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.log_level).data()
|
||||
<< "level_num" << msg.log_level << "message" << std::string(msg.payload.begin(), msg.payload.end())
|
||||
<< "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
<< static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
|
@@ -29,7 +29,7 @@ template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> null_logger_mt(const std::string &logger_name)
|
||||
{
|
||||
auto null_logger = Factory::template create<sinks::null_sink_mt>(logger_name);
|
||||
null_logger->set_level(log_level::off);
|
||||
null_logger->set_level(level::off);
|
||||
return null_logger;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> null_logger_st(const std::string &logger_name)
|
||||
{
|
||||
auto null_logger = Factory::template create<sinks::null_sink_st>(logger_name);
|
||||
null_logger->set_level(log_level::off);
|
||||
null_logger->set_level(level::off);
|
||||
return null_logger;
|
||||
}
|
||||
|
||||
|
@@ -86,23 +86,23 @@ public:
|
||||
QTextCharFormat format;
|
||||
// trace
|
||||
format.setForeground(dark_colors ? Qt::darkGray : Qt::gray);
|
||||
colors_.at(log_level::trace) = format;
|
||||
colors_.at(level::trace) = format;
|
||||
// debug
|
||||
format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan);
|
||||
colors_.at(log_level::debug) = format;
|
||||
colors_.at(level::debug) = format;
|
||||
// info
|
||||
format.setForeground(dark_colors ? Qt::darkGreen : Qt::green);
|
||||
colors_.at(log_level::info) = format;
|
||||
colors_.at(level::info) = format;
|
||||
// warn
|
||||
format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow);
|
||||
colors_.at(spdlog::log_level::warn) = format;
|
||||
colors_.at(spdlog::level::warn) = format;
|
||||
// err
|
||||
format.setForeground(Qt::red);
|
||||
colors_.at(log_level::err) = format;
|
||||
colors_.at(level::err) = format;
|
||||
// critical
|
||||
format.setForeground(Qt::white);
|
||||
format.setBackground(Qt::red);
|
||||
colors_.at(log_level::critical) = format;
|
||||
colors_.at(level::critical) = format;
|
||||
}
|
||||
|
||||
~qt_color_sink()
|
||||
@@ -116,13 +116,13 @@ public:
|
||||
default_color_ = format;
|
||||
}
|
||||
|
||||
void set_level_color(log_level color_level, QTextCharFormat format)
|
||||
void set_level_color(level color_level, QTextCharFormat format)
|
||||
{
|
||||
// std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
colors_.at(static_cast<size_t>(color_level)) = format;
|
||||
}
|
||||
|
||||
QTextCharFormat &get_level_color(log_level color_level)
|
||||
QTextCharFormat &get_level_color(level color_level)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
return colors_.at(static_cast<size_t>(color_level));
|
||||
@@ -185,7 +185,7 @@ protected:
|
||||
qt_text_edit_, // text edit to append to
|
||||
std::move(payload), // text to append
|
||||
default_color_, // default color
|
||||
colors_.at(msg.level), // color to apply
|
||||
colors_.at(msg.log_level), // color to apply
|
||||
color_range_start, // color range start
|
||||
color_range_end}; // color range end
|
||||
|
||||
@@ -238,7 +238,7 @@ protected:
|
||||
int max_lines_;
|
||||
bool is_utf8_;
|
||||
QTextCharFormat default_color_;
|
||||
std::array<QTextCharFormat, log_level::n_levels> colors_;
|
||||
std::array<QTextCharFormat, level::n_levels> colors_;
|
||||
};
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
|
@@ -9,17 +9,16 @@
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
||||
SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::log_level msg_level) const
|
||||
SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level msg_level) const
|
||||
{
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::sinks::sink::set_level(log_level log_level)
|
||||
SPDLOG_INLINE void spdlog::sinks::sink::set_level(level level)
|
||||
{
|
||||
level_.store(log_level, std::memory_order_relaxed);
|
||||
level_.store(level, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog::log_level spdlog::sinks::sink::level() const
|
||||
{
|
||||
return static_cast<spdlog::log_level>(level_.load(std::memory_order_relaxed));
|
||||
SPDLOG_INLINE spdlog::level spdlog::sinks::sink::log_level() const {
|
||||
return static_cast<spdlog::level>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
@@ -18,13 +18,13 @@ public:
|
||||
virtual void set_pattern(const std::string &pattern) = 0;
|
||||
virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0;
|
||||
|
||||
void set_level(log_level log_level);
|
||||
log_level level() const;
|
||||
bool should_log(log_level msg_level) const;
|
||||
void set_level(level level);
|
||||
level log_level() const;
|
||||
bool should_log(level msg_level) const;
|
||||
|
||||
protected:
|
||||
// sink log level - default is all
|
||||
atomic_level_t level_{log_level::trace};
|
||||
atomic_level_t level_{level::trace};
|
||||
};
|
||||
|
||||
} // namespace sinks
|
||||
|
@@ -23,13 +23,13 @@ class syslog_sink : public base_sink<Mutex>
|
||||
public:
|
||||
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
||||
: enable_formatting_{enable_formatting}
|
||||
, syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG,
|
||||
/* spdlog::log_level::debug */ LOG_DEBUG,
|
||||
/* spdlog::log_level::info */ LOG_INFO,
|
||||
/* spdlog::log_level::warn */ LOG_WARNING,
|
||||
/* spdlog::log_level::err */ LOG_ERR,
|
||||
/* spdlog::log_level::critical */ LOG_CRIT,
|
||||
/* spdlog::log_level::off */ LOG_INFO}}
|
||||
, syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO}}
|
||||
, ident_{std::move(ident)}
|
||||
{
|
||||
// set ident to be program name if empty
|
||||
@@ -84,7 +84,7 @@ private:
|
||||
//
|
||||
int syslog_prio_from_level(const details::log_msg &msg) const
|
||||
{
|
||||
return syslog_levels_.at(static_cast<levels_array::size_type>(msg.level));
|
||||
return syslog_levels_.at(static_cast<levels_array::size_type>(msg.log_level));
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -27,13 +27,13 @@ public:
|
||||
systemd_sink(std::string ident = "", bool enable_formatting = false)
|
||||
: ident_{std::move(ident)}
|
||||
, enable_formatting_{enable_formatting}
|
||||
, syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG,
|
||||
/* spdlog::log_level::debug */ LOG_DEBUG,
|
||||
/* spdlog::log_level::info */ LOG_INFO,
|
||||
/* spdlog::log_level::warn */ LOG_WARNING,
|
||||
/* spdlog::log_level::err */ LOG_ERR,
|
||||
/* spdlog::log_level::critical */ LOG_CRIT,
|
||||
/* spdlog::log_level::off */ LOG_INFO}}
|
||||
, syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO}}
|
||||
{}
|
||||
|
||||
~systemd_sink() override {}
|
||||
@@ -75,7 +75,7 @@ protected:
|
||||
if (msg.source.empty())
|
||||
{
|
||||
// Note: function call inside '()' to avoid macro expansion
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d", syslog_level(msg.level),
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d", syslog_level(msg.log_level),
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
"TID=%zu", details::os::thread_id(),
|
||||
#endif
|
||||
@@ -83,7 +83,7 @@ protected:
|
||||
}
|
||||
else
|
||||
{
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d", syslog_level(msg.level),
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d", syslog_level(msg.log_level),
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
"TID=%zu", details::os::thread_id(),
|
||||
#endif
|
||||
@@ -97,7 +97,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
int syslog_level(log_level l)
|
||||
int syslog_level(level l)
|
||||
{
|
||||
return syslog_levels_.at(static_cast<levels_array::size_type>(l));
|
||||
}
|
||||
|
@@ -172,21 +172,21 @@ struct eventlog
|
||||
{
|
||||
static WORD get_event_type(details::log_msg const &msg)
|
||||
{
|
||||
switch (msg.level)
|
||||
switch (msg.log_level)
|
||||
{
|
||||
case log_level::trace:
|
||||
case log_level::debug:
|
||||
case level::trace:
|
||||
case level::debug:
|
||||
return EVENTLOG_SUCCESS;
|
||||
|
||||
case log_level::info:
|
||||
case level::info:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
|
||||
case spdlog::log_level::warn:
|
||||
case spdlog::level::warn:
|
||||
return EVENTLOG_WARNING_TYPE;
|
||||
|
||||
case log_level::err:
|
||||
case log_level::critical:
|
||||
case log_level::off:
|
||||
case level::err:
|
||||
case level::critical:
|
||||
case level::off:
|
||||
return EVENTLOG_ERROR_TYPE;
|
||||
|
||||
default:
|
||||
@@ -196,7 +196,7 @@ struct eventlog
|
||||
|
||||
static WORD get_event_category(details::log_msg const &msg)
|
||||
{
|
||||
return (WORD)msg.level;
|
||||
return (WORD)msg.log_level;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -24,14 +24,14 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
|
||||
|
||||
set_color_mode_impl(mode);
|
||||
// set level colors
|
||||
colors_.at(to_size_t(log_level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||
colors_.at(to_size_t(log_level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
|
||||
colors_.at(to_size_t(log_level::info)) = FOREGROUND_GREEN; // green
|
||||
colors_.at(to_size_t(spdlog::log_level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
|
||||
colors_.at(to_size_t(log_level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
|
||||
colors_.at(to_size_t(log_level::critical)) =
|
||||
colors_.at(to_size_t(level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||
colors_.at(to_size_t(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
|
||||
colors_.at(to_size_t(level::info)) = FOREGROUND_GREEN; // green
|
||||
colors_.at(to_size_t(spdlog::level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
|
||||
colors_.at(to_size_t(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
|
||||
colors_.at(to_size_t(level::critical)) =
|
||||
BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background
|
||||
colors_.at(to_size_t(log_level::off)) = 0;
|
||||
colors_.at(to_size_t(level::off)) = 0;
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
@@ -42,7 +42,7 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::~wincolor_sink()
|
||||
|
||||
// change the color for the given level
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color(log_level level, std::uint16_t color)
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color(level level, std::uint16_t color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_[static_cast<size_t>(level)] = color;
|
||||
@@ -66,7 +66,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
// before color range
|
||||
print_range_(formatted, 0, msg.color_range_start);
|
||||
// in color range
|
||||
auto orig_attribs = static_cast<WORD>(set_foreground_color_(colors_[static_cast<size_t>(msg.level)]));
|
||||
auto orig_attribs = static_cast<WORD>(set_foreground_color_(colors_[static_cast<size_t>(msg.log_level)]));
|
||||
print_range_(formatted, msg.color_range_start, msg.color_range_end);
|
||||
// reset to orig colors
|
||||
::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), orig_attribs);
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
wincolor_sink &operator=(const wincolor_sink &other) = delete;
|
||||
|
||||
// change the color for the given level
|
||||
void set_color(log_level level, std::uint16_t color);
|
||||
void set_color(level level, std::uint16_t color);
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) override final;
|
||||
|
@@ -32,24 +32,24 @@ SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE log_level get_level()
|
||||
SPDLOG_INLINE level get_level()
|
||||
{
|
||||
return default_logger_raw()->level();
|
||||
return default_logger_raw()->log_level();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool should_log(log_level log_level)
|
||||
SPDLOG_INLINE bool should_log(level level)
|
||||
{
|
||||
return default_logger_raw()->should_log(log_level);
|
||||
return default_logger_raw()->should_log(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void set_level(log_level log_level)
|
||||
SPDLOG_INLINE void set_level(level level)
|
||||
{
|
||||
details::registry::instance().set_level(log_level);
|
||||
details::registry::instance().set_level(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void flush_on(log_level log_level)
|
||||
SPDLOG_INLINE void flush_on(level level)
|
||||
{
|
||||
details::registry::instance().flush_on(log_level);
|
||||
details::registry::instance().flush_on(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg))
|
||||
|
@@ -59,16 +59,16 @@ SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
|
||||
SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||
|
||||
// Get global logging level
|
||||
SPDLOG_API log_level get_level();
|
||||
SPDLOG_API level get_level();
|
||||
|
||||
// Set global logging level
|
||||
SPDLOG_API void set_level(log_level log_level);
|
||||
SPDLOG_API void set_level(level level);
|
||||
|
||||
// Determine whether the default logger should log messages with a certain level
|
||||
SPDLOG_API bool should_log(log_level lvl);
|
||||
SPDLOG_API bool should_log(level lvl);
|
||||
|
||||
// Set global flush level
|
||||
SPDLOG_API void flush_on(log_level log_level);
|
||||
SPDLOG_API void flush_on(level level);
|
||||
|
||||
// Start/Restart a periodic flusher thread
|
||||
// Warning: Use only if all your loggers are thread safe!
|
||||
@@ -132,25 +132,25 @@ SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logge
|
||||
SPDLOG_API void apply_logger_env_levels(std::shared_ptr<logger> logger);
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(source_loc source, log_level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(source_loc source, level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(log_level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
inline void log(level lvl, format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
|
||||
inline void log(source_loc loc, log_level lvl, S fmt, Args &&...args)
|
||||
inline void log(source_loc loc, level lvl, S fmt, Args &&...args)
|
||||
{
|
||||
default_logger_raw()->log(loc, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
|
||||
inline void log(log_level lvl, S fmt, Args &&...args)
|
||||
inline void log(level lvl, S fmt, Args &&...args)
|
||||
{
|
||||
default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -159,135 +159,135 @@ inline void log(log_level lvl, S fmt, Args &&...args)
|
||||
template<typename... Args>
|
||||
inline void trace(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::info, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, spdlog::log_level::warn, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, spdlog::level::warn, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::err, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(loc_with_fmt fmt, Args &&...args)
|
||||
{
|
||||
log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// log functions with no format string, just string
|
||||
inline void trace(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::trace, msg);
|
||||
log(loc, level::trace, msg);
|
||||
}
|
||||
|
||||
inline void debug(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::debug, msg);
|
||||
log(loc, level::debug, msg);
|
||||
}
|
||||
|
||||
inline void info(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::info, msg);
|
||||
log(loc, level::info, msg);
|
||||
}
|
||||
|
||||
inline void warn(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, spdlog::log_level::warn, msg);
|
||||
log(loc, spdlog::level::warn, msg);
|
||||
}
|
||||
|
||||
inline void error(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::err, msg);
|
||||
log(loc, level::err, msg);
|
||||
}
|
||||
|
||||
inline void critical(string_view_t msg, source_loc loc = source_loc::current())
|
||||
{
|
||||
log(loc, log_level::critical, msg);
|
||||
log(loc, level::critical, msg);
|
||||
}
|
||||
#else
|
||||
template<typename... Args>
|
||||
inline void trace(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::trace, fmt, std::forward<Args>(args)...);
|
||||
log(level::trace, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::debug, fmt, std::forward<Args>(args)...);
|
||||
log(level::debug, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::info, fmt, std::forward<Args>(args)...);
|
||||
log(level::info, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::warn, fmt, std::forward<Args>(args)...);
|
||||
log(level::warn, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::err, fmt, std::forward<Args>(args)...);
|
||||
log(level::err, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(format_string_t<Args...> fmt, Args &&...args)
|
||||
{
|
||||
log(log_level::critical, fmt, std::forward<Args>(args)...);
|
||||
log(level::critical, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// log functions with no format string, just string
|
||||
inline void trace(string_view_t msg)
|
||||
{
|
||||
log(log_level::trace, msg);
|
||||
log(level::trace, msg);
|
||||
}
|
||||
|
||||
inline void debug(string_view_t msg)
|
||||
{
|
||||
log(log_level::debug, msg);
|
||||
log(level::debug, msg);
|
||||
}
|
||||
|
||||
inline void info(string_view_t msg)
|
||||
{
|
||||
log(log_level::info, msg);
|
||||
log(level::info, msg);
|
||||
}
|
||||
|
||||
inline void warn(string_view_t msg)
|
||||
{
|
||||
log(log_level::warn, msg);
|
||||
log(level::warn, msg);
|
||||
}
|
||||
|
||||
inline void error(string_view_t msg)
|
||||
{
|
||||
log(log_level::err, msg);
|
||||
log(level::err, msg);
|
||||
}
|
||||
|
||||
inline void critical(string_view_t msg)
|
||||
{
|
||||
log(log_level::critical, msg);
|
||||
log(level::critical, msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -314,7 +314,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
|
||||
# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::trace, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
||||
# define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
|
||||
@@ -322,7 +322,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
|
||||
# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::debug, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
|
||||
# define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
|
||||
@@ -330,7 +330,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
|
||||
# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::info, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
|
||||
# define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_INFO(logger, ...) (void)0
|
||||
@@ -338,7 +338,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
|
||||
# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::warn, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
|
||||
# define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_WARN(logger, ...) (void)0
|
||||
@@ -346,7 +346,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
|
||||
# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::err, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
|
||||
# define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
|
||||
@@ -354,7 +354,7 @@ inline void critical(string_view_t msg)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
|
||||
# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::critical, __VA_ARGS__)
|
||||
# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
|
||||
# define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
# define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
|
||||
|
Reference in New Issue
Block a user