null_atomic_log_level and fix compile

This commit is contained in:
gabime 2023-09-23 00:27:32 +03:00
parent ac2955cb48
commit 392917f855
45 changed files with 365 additions and 365 deletions

View File

@ -73,7 +73,7 @@ int main()
spdlog::info("Positional args are {1} {0}..", "too", "supported"); spdlog::info("Positional args are {1} {0}..", "too", "supported");
spdlog::info("{:<30}", "left aligned"); spdlog::info("{:<30}", "left aligned");
spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::set_level(spdlog::log_level::debug); // Set global log level to debug
spdlog::debug("This message should be displayed.."); spdlog::debug("This message should be displayed..");
// change log pattern // change log pattern
@ -220,14 +220,14 @@ void binary_example()
void multi_sink_example() void multi_sink_example()
{ {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn); console_sink->set_level(spdlog::log_level::warn);
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true); auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
file_sink->set_level(spdlog::level::trace); file_sink->set_level(spdlog::log_level::trace);
spdlog::logger logger("multi_sink", {console_sink, file_sink}); spdlog::logger logger("multi_sink", {console_sink, file_sink});
logger.set_level(spdlog::level::debug); logger.set_level(spdlog::log_level::debug);
logger.warn("this should appear in both console and file"); logger.warn("this should appear in both console and file");
logger.info("this message should not appear in the console, only in the file"); logger.info("this message should not appear in the console, only in the file");
} }
@ -244,7 +244,7 @@ void callback_example()
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg &msg) { auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg &msg) {
// for example you can be notified by sending an email to yourself // for example you can be notified by sending an email to yourself
}); });
callback_sink->set_level(spdlog::level::err); callback_sink->set_level(spdlog::log_level::err);
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
spdlog::logger logger("custom_callback_logger", {console_sink, callback_sink}); spdlog::logger logger("custom_callback_logger", {console_sink, callback_sink});

View File

@ -56,7 +56,7 @@ void bench_threaded_logging(size_t threads, int iters)
spdlog::info(""); spdlog::info("");
auto empty_logger = std::make_shared<spdlog::logger>("level-off"); auto empty_logger = std::make_shared<spdlog::logger>("level-off");
empty_logger->set_level(spdlog::level::off); empty_logger->set_level(spdlog::log_level::off);
bench(iters, empty_logger); bench(iters, empty_logger);
} }
@ -79,7 +79,7 @@ void bench_single_threaded(int iters)
spdlog::info(""); spdlog::info("");
auto empty_logger = std::make_shared<spdlog::logger>("level-off"); auto empty_logger = std::make_shared<spdlog::logger>("level-off");
empty_logger->set_level(spdlog::level::off); empty_logger->set_level(spdlog::log_level::off);
bench(iters, empty_logger); bench(iters, empty_logger);
} }
@ -208,7 +208,7 @@ void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log)
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
for (auto i = 0; i < howmany; ++i) for (auto i = 0; i < howmany; ++i)
{ {
spdlog::log(spdlog::level::info, msg); spdlog::log(spdlog::log_level::info, msg);
} }
auto delta = high_resolution_clock::now() - start; auto delta = high_resolution_clock::now() - start;

View File

@ -16,7 +16,7 @@ void bench_formatter(benchmark::State &state, std::string pattern)
const char *text = "Hello. This is some message with length of 80 "; const char *text = "Hello. This is some message with length of 80 ";
spdlog::source_loc source_loc{"a/b/c/d/myfile.cpp", 123, "some_func()"}; spdlog::source_loc source_loc{"a/b/c/d/myfile.cpp", 123, "some_func()"};
spdlog::details::log_msg msg(source_loc, logger_name, spdlog::level::info, text); spdlog::details::log_msg msg(source_loc, logger_name, spdlog::log_level::info, text);
for (auto _ : state) for (auto _ : state)
{ {

View File

@ -97,7 +97,7 @@ int main(int argc, char *argv[])
// disabled loggers // disabled loggers
auto disabled_logger = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>()); auto disabled_logger = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
disabled_logger->set_level(spdlog::level::off); disabled_logger->set_level(spdlog::log_level::off);
benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger); benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger);
benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger, disabled_logger); benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger, disabled_logger);
benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger); benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);

View File

@ -47,16 +47,16 @@ int main(int, char *[])
spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left"); spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left");
// Runtime log levels // Runtime log levels
spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::set_level(spdlog::log_level::info); // Set global log level to info
spdlog::debug("This message should not be displayed!"); spdlog::debug("This message should not be displayed!");
spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::set_level(spdlog::log_level::trace); // Set specific logger's log level
spdlog::debug("This message should be displayed.."); spdlog::debug("This message should be displayed..");
// Customize msg format for all loggers // Customize msg format for all loggers
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"); spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v");
spdlog::info("This an info message with custom format"); spdlog::info("This an info message with custom format");
spdlog::set_pattern("%+"); // back to default format spdlog::set_pattern("%+"); // back to default format
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
try try
{ {
@ -243,7 +243,7 @@ void udp_example()
{ {
spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091); spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091);
auto my_logger = spdlog::udp_logger_mt("udplog", cfg); auto my_logger = spdlog::udp_logger_mt("udplog", cfg);
my_logger->set_level(spdlog::level::debug); my_logger->set_level(spdlog::log_level::debug);
my_logger->info("hello world"); my_logger->info("hello world");
} }
@ -251,14 +251,14 @@ void udp_example()
void multi_sink_example() void multi_sink_example()
{ {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn); console_sink->set_level(spdlog::log_level::warn);
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true); auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
file_sink->set_level(spdlog::level::trace); file_sink->set_level(spdlog::log_level::trace);
spdlog::logger logger("multi_sink", {console_sink, file_sink}); spdlog::logger logger("multi_sink", {console_sink, file_sink});
logger.set_level(spdlog::level::debug); logger.set_level(spdlog::log_level::debug);
logger.warn("this should appear in both console and file"); logger.warn("this should appear in both console and file");
logger.info("this message should not appear in the console, only in the file"); logger.info("this message should not appear in the console, only in the file");
} }
@ -378,9 +378,9 @@ void replace_default_logger_example()
auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true); auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true);
spdlog::set_default_logger(new_logger); spdlog::set_default_logger(new_logger);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
spdlog::debug("This message should not be displayed!"); spdlog::debug("This message should not be displayed!");
spdlog::set_level(spdlog::level::trace); spdlog::set_level(spdlog::log_level::trace);
spdlog::debug("This message should be displayed.."); spdlog::debug("This message should be displayed..");
spdlog::set_default_logger(old_logger); spdlog::set_default_logger(old_logger);

View File

@ -87,17 +87,17 @@ SPDLOG_INLINE void load_levels(const std::string &input)
} }
auto key_vals = extract_key_vals_(input); auto key_vals = extract_key_vals_(input);
std::unordered_map<std::string, level::level_enum> levels; std::unordered_map<std::string, log_level> levels;
level::level_enum global_level = level::info; log_level global_level = log_level::info;
bool global_level_found = false; bool global_level_found = false;
for (auto &name_level : key_vals) for (auto &name_level : key_vals)
{ {
auto &logger_name = name_level.first; const auto &logger_name = name_level.first;
auto level_name = to_lower_(name_level.second); auto level_name = to_lower_(name_level.second);
auto level = level::from_str(level_name); auto level = level_from_str(level_name);
// ignore unrecognized level names // ignore unrecognized level names
if (level == level::off && level_name != "off") if (level == log_level::off && level_name != "off")
{ {
continue; continue;
} }

View File

@ -11,32 +11,24 @@
#include <iterator> #include <iterator>
namespace spdlog { namespace spdlog {
namespace level {
//#if __cplusplus >= 201703L SPDLOG_INLINE spdlog::log_level level_from_str(const std::string &name) noexcept
//constexpr
//#endif
// static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) noexcept
{ {
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); const auto *it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
if (it != std::end(level_string_views)) if (it != std::end(level_string_views))
return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it)); return static_cast<log_level>(std::distance(std::begin(level_string_views), it));
// check also for "warn" and "err" before giving up.. // check also for "warn" and "err" before giving up..
if (name == "warn") if (name == "warn")
{ {
return level::warn; return spdlog::log_level::warn;
} }
if (name == "err") if (name == "err")
{ {
return level::err; return log_level::err;
} }
return level::off; return log_level::off;
} }
} // namespace level
SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
: msg_(std::move(msg)) : msg_(std::move(msg))

View File

@ -142,11 +142,6 @@ using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
# define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) # define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x)
#endif // SPDLOG_USE_STD_FORMAT #endif // SPDLOG_USE_STD_FORMAT
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_int;
#else
using level_t = std::atomic<int>;
#endif
#define SPDLOG_LEVEL_TRACE 0 #define SPDLOG_LEVEL_TRACE 0
#define SPDLOG_LEVEL_DEBUG 1 #define SPDLOG_LEVEL_DEBUG 1
@ -165,8 +160,7 @@ template<typename T>
using is_convertible_to_sv = std::enable_if_t<std::is_convertible_v<T, string_view_t>>; using is_convertible_to_sv = std::enable_if_t<std::is_convertible_v<T, string_view_t>>;
// Log level enum // Log level enum
namespace level { enum class log_level
enum level_enum : int
{ {
trace = SPDLOG_LEVEL_TRACE, trace = SPDLOG_LEVEL_TRACE,
debug = SPDLOG_LEVEL_DEBUG, debug = SPDLOG_LEVEL_DEBUG,
@ -178,6 +172,12 @@ enum level_enum : int
n_levels n_levels
}; };
#if not defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_log_level;
#else
using level_t = std::atomic<log_level>;
#endif
#if !defined(SPDLOG_LEVEL_NAMES) #if !defined(SPDLOG_LEVEL_NAMES)
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off"} #define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off"}
#endif #endif
@ -186,22 +186,27 @@ enum level_enum : int
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"} #define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"}
#endif #endif
constexpr std::array<string_view_t, level_enum::n_levels> level_string_views SPDLOG_LEVEL_NAMES; constexpr size_t to_size_t(log_level level) noexcept
constexpr std::array<const char *, level_enum::n_levels>short_level_names SPDLOG_SHORT_LEVEL_NAMES;
constexpr string_view_t to_string_view(spdlog::level::level_enum lvl) noexcept
{ {
return level_string_views.at(lvl); return static_cast<size_t>(level);
}
constexpr auto levels_count = to_size_t(log_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
{
return level_string_views.at(to_size_t(lvl));
} }
constexpr const char *to_short_c_str(spdlog::level::level_enum lvl) noexcept constexpr const char *to_short_c_str(spdlog::log_level lvl) noexcept
{ {
return short_level_names.at(lvl); return short_level_names.at(to_size_t(lvl));
} }
SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) noexcept; SPDLOG_API spdlog::log_level level_from_str(const std::string &name) noexcept;
} // namespace level
// //
// Color mode used by sinks with color support. // Color mode used by sinks with color support.

View File

@ -13,7 +13,7 @@ namespace spdlog {
namespace details { 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_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name,
spdlog::level::level_enum lvl, spdlog::string_view_t msg) spdlog::log_level lvl, spdlog::string_view_t msg)
: logger_name(a_logger_name) : logger_name(a_logger_name)
, level(lvl) , level(lvl)
, time(log_time) , time(log_time)
@ -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_INLINE log_msg::log_msg(
spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) spdlog::source_loc loc, string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg)
: log_msg(os::now(), loc, a_logger_name, lvl, msg) : log_msg(os::now(), loc, a_logger_name, lvl, msg)
{} {}
SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg)
: log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg)
{} {}

View File

@ -11,14 +11,14 @@ namespace details {
struct SPDLOG_API log_msg struct SPDLOG_API log_msg
{ {
log_msg() = default; log_msg() = default;
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 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, level::level_enum 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, level::level_enum lvl, string_view_t msg); log_msg(string_view_t logger_name, log_level lvl, string_view_t msg);
log_msg(const log_msg &other) = default; log_msg(const log_msg &other) = default;
log_msg &operator=(const log_msg &other) = default; log_msg &operator=(const log_msg &other) = default;
string_view_t logger_name; string_view_t logger_name;
level::level_enum level{level::off}; log_level level{log_level::off};
log_clock::time_point time; log_clock::time_point time;
size_t thread_id{0}; size_t thread_id{0};

View File

@ -5,9 +5,12 @@
#include <atomic> #include <atomic>
#include <utility> #include <utility>
// null, no cost dummy "mutex" and dummy "atomic" int // null, no cost dummy "mutex" and dummy "atomic" int
namespace spdlog { namespace spdlog {
enum class log_level; // forward declaration
namespace details { namespace details {
struct null_mutex struct null_mutex
{ {
@ -15,26 +18,26 @@ struct null_mutex
void unlock() const {} void unlock() const {}
}; };
struct null_atomic_int struct null_atomic_log_level
{ {
int value; spdlog::log_level value;
null_atomic_int() = default; null_atomic_log_level() = default;
explicit null_atomic_int(int new_value) explicit null_atomic_log_level(spdlog::log_level new_value)
: value(new_value) : value(new_value)
{} {}
int load(std::memory_order = std::memory_order_relaxed) const [[nodiscard]] log_level load(std::memory_order = std::memory_order_relaxed) const
{ {
return value; return value;
} }
void store(int new_value, std::memory_order = std::memory_order_relaxed) void store(log_level new_value, std::memory_order = std::memory_order_relaxed)
{ {
value = new_value; value = new_value;
} }
int exchange(int new_value, std::memory_order = std::memory_order_relaxed) log_level exchange(log_level new_value, std::memory_order = std::memory_order_relaxed)
{ {
std::swap(new_value, value); std::swap(new_value, value);
return new_value; // return value before the call return new_value; // return value before the call

View File

@ -142,7 +142,7 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
} }
} }
SPDLOG_INLINE void registry::set_level(level::level_enum log_level) SPDLOG_INLINE void registry::set_level(log_level log_level)
{ {
std::lock_guard<std::mutex> lock(logger_map_mutex_); std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (auto &l : loggers_) for (auto &l : loggers_)
@ -152,7 +152,7 @@ SPDLOG_INLINE void registry::set_level(level::level_enum log_level)
global_log_level_ = log_level; global_log_level_ = log_level;
} }
SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) SPDLOG_INLINE void registry::flush_on(log_level log_level)
{ {
std::lock_guard<std::mutex> lock(logger_map_mutex_); std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (auto &l : loggers_) for (auto &l : loggers_)
@ -235,7 +235,7 @@ SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registrat
automatic_registration_ = automatic_registration; automatic_registration_ = automatic_registration;
} }
SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *global_level) SPDLOG_INLINE void registry::set_levels(log_levels levels, log_level *global_level)
{ {
std::lock_guard<std::mutex> lock(logger_map_mutex_); std::lock_guard<std::mutex> lock(logger_map_mutex_);
log_levels_ = std::move(levels); log_levels_ = std::move(levels);

View File

@ -27,7 +27,7 @@ class thread_pool;
class SPDLOG_API registry class SPDLOG_API registry
{ {
public: public:
using log_levels = std::unordered_map<std::string, level::level_enum>; using log_levels = std::unordered_map<std::string, log_level>;
registry(const registry &) = delete; registry(const registry &) = delete;
registry &operator=(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 // 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_formatter(std::unique_ptr<formatter> formatter);
void set_level(level::level_enum log_level); void set_level(log_level log_level);
void flush_on(level::level_enum log_level); void flush_on(log_level log_level);
template<typename Rep, typename Period> template<typename Rep, typename Period>
void flush_every(std::chrono::duration<Rep, Period> interval) void flush_every(std::chrono::duration<Rep, Period> interval)
@ -83,7 +83,7 @@ public:
void set_automatic_registration(bool automatic_registration); void set_automatic_registration(bool automatic_registration);
// set levels for all existing/future loggers. global_level can be null if should not set. // set levels for all existing/future loggers. global_level can be null if should not set.
void set_levels(log_levels levels, level::level_enum *global_level); void set_levels(log_levels levels, log_level *global_level);
static registry &instance(); static registry &instance();
@ -101,8 +101,8 @@ private:
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_; std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
log_levels log_levels_; log_levels log_levels_;
std::unique_ptr<formatter> formatter_; std::unique_ptr<formatter> formatter_;
spdlog::level::level_enum global_log_level_ = level::info; spdlog::log_level global_log_level_ = log_level::info;
level::level_enum flush_level_ = level::off; log_level flush_level_ = log_level::off;
err_handler err_handler_; err_handler err_handler_;
std::shared_ptr<thread_pool> tp_; std::shared_ptr<thread_pool> tp_;
std::unique_ptr<periodic_worker> periodic_flusher_; std::unique_ptr<periodic_worker> periodic_flusher_;

View File

@ -31,14 +31,14 @@ SPDLOG_INLINE logger::logger(logger &&other) noexcept
, custom_err_handler_(std::move(other.custom_err_handler_)) , custom_err_handler_(std::move(other.custom_err_handler_))
{} {}
SPDLOG_INLINE void logger::set_level(level::level_enum log_level) SPDLOG_INLINE void logger::set_level(log_level log_level)
{ {
level_.store(log_level); level_.store(log_level);
} }
SPDLOG_INLINE level::level_enum logger::level() const SPDLOG_INLINE log_level logger::level() const
{ {
return static_cast<level::level_enum>(level_.load(std::memory_order_relaxed)); return static_cast<log_level>(level_.load(std::memory_order_relaxed));
} }
SPDLOG_INLINE const std::string &logger::name() const SPDLOG_INLINE const std::string &logger::name() const
@ -77,14 +77,14 @@ SPDLOG_INLINE void logger::flush()
flush_(); flush_();
} }
SPDLOG_INLINE void logger::flush_on(level::level_enum log_level) SPDLOG_INLINE void logger::flush_on(log_level log_level)
{ {
flush_level_.store(log_level); flush_level_.store(log_level);
} }
SPDLOG_INLINE level::level_enum logger::flush_level() const SPDLOG_INLINE log_level logger::flush_level() const
{ {
return static_cast<level::level_enum>(flush_level_.load(std::memory_order_relaxed)); return static_cast<log_level>(flush_level_.load(std::memory_order_relaxed));
} }
// sinks // sinks
@ -127,7 +127,7 @@ SPDLOG_INLINE void logger::flush_()
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg)
{ {
auto flush_level = flush_level_.load(std::memory_order_relaxed); auto flush_level = flush_level_.load(std::memory_order_relaxed);
return (msg.level >= flush_level) && (msg.level != level::off); return (msg.level >= flush_level) && (msg.level != log_level::off);
} }
SPDLOG_INLINE void logger::err_handler_(const std::string &msg) SPDLOG_INLINE void logger::err_handler_(const std::string &msg)

View File

@ -77,7 +77,7 @@ public:
// log functions // log functions
template<typename... Args> template<typename... Args>
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) void log(source_loc loc, log_level lvl, format_string_t<Args...> fmt, Args &&...args)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -86,7 +86,7 @@ public:
} }
template<typename... Args> template<typename... Args>
void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) void log(log_level lvl, format_string_t<Args...> fmt, Args &&...args)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -95,7 +95,7 @@ public:
} }
template<typename S, typename = is_convertible_to_sv<S>, typename... Args> template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
void log(source_loc loc, level::level_enum lvl, S fmt, Args &&...args) void log(source_loc loc, log_level lvl, S fmt, Args &&...args)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -104,7 +104,7 @@ public:
} }
// log with no format string, just string message // log with no format string, just string message
void log(source_loc loc, level::level_enum lvl, string_view_t msg) void log(source_loc loc, log_level lvl, string_view_t msg)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -112,7 +112,7 @@ public:
} }
} }
void log(level::level_enum lvl, string_view_t msg) void log(log_level lvl, string_view_t msg)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -121,7 +121,7 @@ public:
} }
// support for custom time // support for custom time
void log(log_clock::time_point log_time, source_loc loc, level::level_enum lvl, string_view_t msg) void log(log_clock::time_point log_time, source_loc loc, log_level lvl, string_view_t msg)
{ {
if (should_log(lvl)) if (should_log(lvl))
{ {
@ -133,150 +133,150 @@ public:
template<typename... Args> template<typename... Args>
void trace(loc_with_fmt fmt, Args &&...args) void trace(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void debug(loc_with_fmt fmt, Args &&...args) void debug(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void info(loc_with_fmt fmt, Args &&...args) void info(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::info, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void warn(loc_with_fmt fmt, Args &&...args) void warn(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::warn, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::warn, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void error(loc_with_fmt fmt, Args &&...args) void error(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::err, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void critical(loc_with_fmt fmt, Args &&...args) void critical(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward<Args>(args)...);
} }
// log functions with no format string, just string // log functions with no format string, just string
void trace(string_view_t msg, source_loc loc = source_loc::current()) void trace(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::trace, msg); log(loc, log_level::trace, msg);
} }
void debug(string_view_t msg, source_loc loc = source_loc::current()) void debug(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::debug, msg); log(loc, log_level::debug, msg);
} }
void info(string_view_t msg, source_loc loc = source_loc::current()) void info(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::info, msg); log(loc, log_level::info, msg);
} }
void warn(string_view_t msg, source_loc loc = source_loc::current()) void warn(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::warn, msg); log(loc, log_level::warn, msg);
} }
void error(string_view_t msg, source_loc loc = source_loc::current()) void error(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::err, msg); log(loc, log_level::err, msg);
} }
void critical(string_view_t msg, source_loc loc = source_loc::current()) void critical(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::critical, msg); log(loc, log_level::critical, msg);
} }
#else #else
template<typename... Args> template<typename... Args>
void trace(format_string_t<Args...> fmt, Args &&...args) void trace(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::trace, fmt, std::forward<Args>(args)...); log(log_level::trace, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void debug(format_string_t<Args...> fmt, Args &&...args) void debug(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::debug, fmt, std::forward<Args>(args)...); log(log_level::debug, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void info(format_string_t<Args...> fmt, Args &&...args) void info(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::info, fmt, std::forward<Args>(args)...); log(log_level::info, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void warn(format_string_t<Args...> fmt, Args &&...args) void warn(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::warn, fmt, std::forward<Args>(args)...); log(log_level::warn, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void error(format_string_t<Args...> fmt, Args &&...args) void error(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::err, fmt, std::forward<Args>(args)...); log(log_level::err, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
void critical(format_string_t<Args...> fmt, Args &&...args) void critical(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::critical, fmt, std::forward<Args>(args)...); log(log_level::critical, fmt, std::forward<Args>(args)...);
} }
// log functions with no format string, just string // log functions with no format string, just string
void trace(string_view_t msg) void trace(string_view_t msg)
{ {
log(level::trace, msg); log(log_level::trace, msg);
} }
void debug(string_view_t msg) void debug(string_view_t msg)
{ {
log(level::debug, msg); log(log_level::debug, msg);
} }
void info(string_view_t msg) void info(string_view_t msg)
{ {
log(level::info, msg); log(log_level::info, msg);
} }
inline void warn(string_view_t msg) inline void warn(string_view_t msg)
{ {
log(level::warn, msg); log(log_level::warn, msg);
} }
void error(string_view_t msg) void error(string_view_t msg)
{ {
log(level::err, msg); log(log_level::err, msg);
} }
void critical(string_view_t msg) void critical(string_view_t msg)
{ {
log(level::critical, msg); log(log_level::critical, msg);
} }
#endif #endif
// return true if logging is enabled for the given level. // return true if logging is enabled for the given level.
[[nodiscard]] bool should_log(level::level_enum msg_level) const [[nodiscard]] bool should_log(log_level msg_level) const
{ {
return msg_level >= level_.load(std::memory_order_relaxed); return msg_level >= level_.load(std::memory_order_relaxed);
} }
// set the level of logging // set the level of logging
void set_level(level::level_enum log_level); void set_level(log_level log_level);
// return the active log level // return the active log level
[[nodiscard]] level::level_enum level() const; [[nodiscard]] log_level level() const;
// return the name of the logger // return the name of the logger
[[nodiscard]] const std::string &name() const; [[nodiscard]] const std::string &name() const;
@ -293,8 +293,8 @@ public:
// flush functions // flush functions
void flush(); void flush();
void flush_on(level::level_enum log_level); void flush_on(log_level log_level);
[[nodiscard]] level::level_enum flush_level() const; [[nodiscard]] log_level flush_level() const;
// sinks // sinks
[[nodiscard]] const std::vector<sink_ptr> &sinks() const; [[nodiscard]] const std::vector<sink_ptr> &sinks() const;
@ -310,13 +310,13 @@ public:
protected: protected:
std::string name_; std::string name_;
std::vector<sink_ptr> sinks_; std::vector<sink_ptr> sinks_;
spdlog::level_t level_{level::info}; spdlog::level_t level_{log_level::info};
spdlog::level_t flush_level_{level::off}; spdlog::level_t flush_level_{log_level::off};
err_handler custom_err_handler_{nullptr}; err_handler custom_err_handler_{nullptr};
// common implementation for after templated public api has been resolved to format string and args // common implementation for after templated public api has been resolved to format string and args
template<typename... Args> template<typename... Args>
void log_with_format_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args) void log_with_format_(source_loc loc, log_level lvl, string_view_t fmt, Args &&...args)
{ {
assert(should_log(lvl)); assert(should_log(lvl));
SPDLOG_TRY SPDLOG_TRY

View File

@ -129,7 +129,7 @@ public:
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
{ {
const string_view_t &level_name = level::to_string_view(msg.level); const string_view_t &level_name = to_string_view(msg.level);
ScopedPadder p(level_name.size(), padinfo_, dest); ScopedPadder p(level_name.size(), padinfo_, dest);
fmt_helper::append_string_view(level_name, 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 void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
{ {
string_view_t level_name{level::to_short_c_str(msg.level)}; string_view_t level_name{to_short_c_str(msg.level)};
ScopedPadder p(level_name.size(), padinfo_, dest); ScopedPadder p(level_name.size(), padinfo_, dest);
fmt_helper::append_string_view(level_name, dest); fmt_helper::append_string_view(level_name, dest);
} }
@ -991,8 +991,8 @@ public:
dest.push_back('['); dest.push_back('[');
// wrap the level name with color // wrap the level name with color
msg.color_range_start = dest.size(); msg.color_range_start = dest.size();
// fmt_helper::append_string_view(level::to_c_str(msg.level), dest); // fmt_helper::append_string_view(log_level::to_c_str(msg.level), dest);
fmt_helper::append_string_view(level::to_string_view(msg.level), dest); fmt_helper::append_string_view(to_string_view(msg.level), dest);
msg.color_range_end = dest.size(); msg.color_range_end = dest.size();
dest.push_back(']'); dest.push_back(']');
dest.push_back(' '); dest.push_back(' ');

View File

@ -92,21 +92,21 @@ private:
return __android_log_buf_write(ID, prio, tag, text); return __android_log_buf_write(ID, prio, tag, text);
} }
static android_LogPriority convert_to_android_(spdlog::level::level_enum level) static android_LogPriority convert_to_android_(spdlog::log_level level)
{ {
switch (level) switch (level)
{ {
case spdlog::level::trace: case spdlog::log_level::trace:
return ANDROID_LOG_VERBOSE; return ANDROID_LOG_VERBOSE;
case spdlog::level::debug: case spdlog::log_level::debug:
return ANDROID_LOG_DEBUG; return ANDROID_LOG_DEBUG;
case spdlog::level::info: case spdlog::log_level::info:
return ANDROID_LOG_INFO; return ANDROID_LOG_INFO;
case spdlog::level::warn: case spdlog::log_level::warn:
return ANDROID_LOG_WARN; return ANDROID_LOG_WARN;
case spdlog::level::err: case spdlog::log_level::err:
return ANDROID_LOG_ERROR; return ANDROID_LOG_ERROR;
case spdlog::level::critical: case spdlog::log_level::critical:
return ANDROID_LOG_FATAL; return ANDROID_LOG_FATAL;
default: default:
return ANDROID_LOG_DEFAULT; return ANDROID_LOG_DEFAULT;

View File

@ -21,17 +21,17 @@ SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, co
{ {
set_color_mode(mode); set_color_mode(mode);
colors_.at(level::trace) = to_string_(white); colors_.at(to_size_t(log_level::trace)) = to_string_(white);
colors_.at(level::debug) = to_string_(cyan); colors_.at(to_size_t(log_level::debug)) = to_string_(cyan);
colors_.at(level::info) = to_string_(green); colors_.at(to_size_t(log_level::info)) = to_string_(green);
colors_.at(level::warn) = to_string_(yellow_bold); colors_.at(to_size_t(log_level::warn)) = to_string_(yellow_bold);
colors_.at(level::err) = to_string_(red_bold); colors_.at(to_size_t(log_level::err)) = to_string_(red_bold);
colors_.at(level::critical) = to_string_(bold_on_red); colors_.at(to_size_t(log_level::critical)) = to_string_(bold_on_red);
colors_.at(level::off) = to_string_(reset); colors_.at(to_size_t(log_level::off)) = to_string_(reset);
} }
template<typename ConsoleMutex> template<typename ConsoleMutex>
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color(level::level_enum color_level, string_view_t color) SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color(log_level color_level, string_view_t color)
{ {
std::lock_guard<mutex_t> lock(mutex_); std::lock_guard<mutex_t> lock(mutex_);
colors_.at(static_cast<size_t>(color_level)) = to_string_(color); colors_.at(static_cast<size_t>(color_level)) = to_string_(color);
@ -126,7 +126,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
template<typename ConsoleMutex> template<typename ConsoleMutex>
SPDLOG_INLINE std::string ansicolor_sink<ConsoleMutex>::to_string_(const string_view_t &sv) SPDLOG_INLINE std::string ansicolor_sink<ConsoleMutex>::to_string_(const string_view_t &sv)
{ {
return std::string(sv.data(), sv.size()); return {sv.data(), sv.size()};
} }
// ansicolor_stdout_sink // ansicolor_stdout_sink

View File

@ -35,7 +35,7 @@ public:
ansicolor_sink &operator=(const ansicolor_sink &other) = delete; ansicolor_sink &operator=(const ansicolor_sink &other) = delete;
ansicolor_sink &operator=(ansicolor_sink &&other) = delete; ansicolor_sink &operator=(ansicolor_sink &&other) = delete;
void set_color(level::level_enum color_level, string_view_t color); void set_color(log_level color_level, string_view_t color);
void set_color_mode(color_mode mode); void set_color_mode(color_mode mode);
bool should_color(); bool should_color();
@ -84,7 +84,7 @@ private:
mutex_t &mutex_; mutex_t &mutex_;
bool should_do_colors_; bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
std::array<std::string, level::n_levels> colors_; std::array<std::string, levels_count> colors_;
void print_ccode_(const string_view_t &color_code); void print_ccode_(const string_view_t &color_code);
void print_range_(const memory_buf_t &formatted, size_t start, size_t end); void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
static std::string to_string_(const string_view_t &sv); static std::string to_string_(const string_view_t &sv);

View File

@ -20,7 +20,7 @@
// #include <spdlog/sinks/dup_filter_sink.h> // #include <spdlog/sinks/dup_filter_sink.h>
// //
// int main() { // int main() {
// auto dup_filter = std::make_shared<dup_filter_sink_st>(std::chrono::seconds(5), level::info); // auto dup_filter = std::make_shared<dup_filter_sink_st>(std::chrono::seconds(5), log_level::info);
// dup_filter->add_sink(std::make_shared<stdout_color_sink_mt>()); // dup_filter->add_sink(std::make_shared<stdout_color_sink_mt>());
// spdlog::logger l("logger", dup_filter); // spdlog::logger l("logger", dup_filter);
// l.info("Hello"); // l.info("Hello");
@ -41,7 +41,7 @@ class dup_filter_sink : public dist_sink<Mutex>
{ {
public: public:
template<class Rep, class Period> template<class Rep, class Period>
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, level::level_enum notification_level = level::info) explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, log_level notification_level = log_level::info)
: max_skip_duration_{max_skip_duration} : max_skip_duration_{max_skip_duration}
, log_level_{notification_level} , log_level_{notification_level}
{} {}
@ -51,7 +51,7 @@ protected:
log_clock::time_point last_msg_time_; log_clock::time_point last_msg_time_;
std::string last_msg_payload_; std::string last_msg_payload_;
size_t skip_counter_ = 0; size_t skip_counter_ = 0;
level::level_enum log_level_; log_level log_level_;
void sink_it_(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {

View File

@ -66,7 +66,7 @@ protected:
if (client_ != nullptr) if (client_ != nullptr)
{ {
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data() 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()) << "level_num" << msg.level << "message" << std::string(msg.payload.begin(), msg.payload.end())
<< "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id" << "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
<< static_cast<int>(msg.thread_id) << finalize; << static_cast<int>(msg.thread_id) << finalize;

View File

@ -29,7 +29,7 @@ template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> null_logger_mt(const std::string &logger_name) 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); auto null_logger = Factory::template create<sinks::null_sink_mt>(logger_name);
null_logger->set_level(level::off); null_logger->set_level(log_level::off);
return null_logger; 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) 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); auto null_logger = Factory::template create<sinks::null_sink_st>(logger_name);
null_logger->set_level(level::off); null_logger->set_level(log_level::off);
return null_logger; return null_logger;
} }

View File

@ -86,23 +86,23 @@ public:
QTextCharFormat format; QTextCharFormat format;
// trace // trace
format.setForeground(dark_colors ? Qt::darkGray : Qt::gray); format.setForeground(dark_colors ? Qt::darkGray : Qt::gray);
colors_.at(level::trace) = format; colors_.at(log_level::trace) = format;
// debug // debug
format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan); format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan);
colors_.at(level::debug) = format; colors_.at(log_level::debug) = format;
// info // info
format.setForeground(dark_colors ? Qt::darkGreen : Qt::green); format.setForeground(dark_colors ? Qt::darkGreen : Qt::green);
colors_.at(level::info) = format; colors_.at(log_level::info) = format;
// warn // warn
format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow); format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow);
colors_.at(level::warn) = format; colors_.at(spdlog::log_level::warn) = format;
// err // err
format.setForeground(Qt::red); format.setForeground(Qt::red);
colors_.at(level::err) = format; colors_.at(log_level::err) = format;
// critical // critical
format.setForeground(Qt::white); format.setForeground(Qt::white);
format.setBackground(Qt::red); format.setBackground(Qt::red);
colors_.at(level::critical) = format; colors_.at(log_level::critical) = format;
} }
~qt_color_sink() ~qt_color_sink()
@ -116,13 +116,13 @@ public:
default_color_ = format; default_color_ = format;
} }
void set_level_color(level::level_enum color_level, QTextCharFormat format) void set_level_color(log_level color_level, QTextCharFormat format)
{ {
// std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_); // std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
colors_.at(static_cast<size_t>(color_level)) = format; colors_.at(static_cast<size_t>(color_level)) = format;
} }
QTextCharFormat &get_level_color(level::level_enum color_level) QTextCharFormat &get_level_color(log_level color_level)
{ {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_); std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
return colors_.at(static_cast<size_t>(color_level)); return colors_.at(static_cast<size_t>(color_level));
@ -238,7 +238,7 @@ protected:
int max_lines_; int max_lines_;
bool is_utf8_; bool is_utf8_;
QTextCharFormat default_color_; QTextCharFormat default_color_;
std::array<QTextCharFormat, level::n_levels> colors_; std::array<QTextCharFormat, log_level::n_levels> colors_;
}; };
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"

View File

@ -9,17 +9,17 @@
#include <spdlog/common.h> #include <spdlog/common.h>
SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::log_level msg_level) const
{ {
return msg_level >= level_.load(std::memory_order_relaxed); return msg_level >= level_.load(std::memory_order_relaxed);
} }
SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) SPDLOG_INLINE void spdlog::sinks::sink::set_level(log_level log_level)
{ {
level_.store(log_level, std::memory_order_relaxed); level_.store(log_level, std::memory_order_relaxed);
} }
SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const SPDLOG_INLINE spdlog::log_level spdlog::sinks::sink::level() const
{ {
return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed)); return static_cast<spdlog::log_level>(level_.load(std::memory_order_relaxed));
} }

View File

@ -18,13 +18,13 @@ public:
virtual void set_pattern(const std::string &pattern) = 0; virtual void set_pattern(const std::string &pattern) = 0;
virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0; virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0;
void set_level(level::level_enum log_level); void set_level(log_level log_level);
level::level_enum level() const; log_level level() const;
bool should_log(level::level_enum msg_level) const; bool should_log(log_level msg_level) const;
protected: protected:
// sink log level - default is all // sink log level - default is all
level_t level_{level::trace}; level_t level_{log_level::trace};
}; };
} // namespace sinks } // namespace sinks

View File

@ -23,13 +23,13 @@ class syslog_sink : public base_sink<Mutex>
public: public:
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
: enable_formatting_{enable_formatting} : enable_formatting_{enable_formatting}
, syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, , syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG,
/* spdlog::level::debug */ LOG_DEBUG, /* spdlog::log_level::debug */ LOG_DEBUG,
/* spdlog::level::info */ LOG_INFO, /* spdlog::log_level::info */ LOG_INFO,
/* spdlog::level::warn */ LOG_WARNING, /* spdlog::log_level::warn */ LOG_WARNING,
/* spdlog::level::err */ LOG_ERR, /* spdlog::log_level::err */ LOG_ERR,
/* spdlog::level::critical */ LOG_CRIT, /* spdlog::log_level::critical */ LOG_CRIT,
/* spdlog::level::off */ LOG_INFO}} /* spdlog::log_level::off */ LOG_INFO}}
, ident_{std::move(ident)} , ident_{std::move(ident)}
{ {
// set ident to be program name if empty // set ident to be program name if empty

View File

@ -27,13 +27,13 @@ public:
systemd_sink(std::string ident = "", bool enable_formatting = false) systemd_sink(std::string ident = "", bool enable_formatting = false)
: ident_{std::move(ident)} : ident_{std::move(ident)}
, enable_formatting_{enable_formatting} , enable_formatting_{enable_formatting}
, syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, , syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG,
/* spdlog::level::debug */ LOG_DEBUG, /* spdlog::log_level::debug */ LOG_DEBUG,
/* spdlog::level::info */ LOG_INFO, /* spdlog::log_level::info */ LOG_INFO,
/* spdlog::level::warn */ LOG_WARNING, /* spdlog::log_level::warn */ LOG_WARNING,
/* spdlog::level::err */ LOG_ERR, /* spdlog::log_level::err */ LOG_ERR,
/* spdlog::level::critical */ LOG_CRIT, /* spdlog::log_level::critical */ LOG_CRIT,
/* spdlog::level::off */ LOG_INFO}} /* spdlog::log_level::off */ LOG_INFO}}
{} {}
~systemd_sink() override {} ~systemd_sink() override {}
@ -97,7 +97,7 @@ protected:
} }
} }
int syslog_level(level::level_enum l) int syslog_level(log_level l)
{ {
return syslog_levels_.at(static_cast<levels_array::size_type>(l)); return syslog_levels_.at(static_cast<levels_array::size_type>(l));
} }

View File

@ -174,19 +174,19 @@ struct eventlog
{ {
switch (msg.level) switch (msg.level)
{ {
case level::trace: case log_level::trace:
case level::debug: case log_level::debug:
return EVENTLOG_SUCCESS; return EVENTLOG_SUCCESS;
case level::info: case log_level::info:
return EVENTLOG_INFORMATION_TYPE; return EVENTLOG_INFORMATION_TYPE;
case level::warn: case spdlog::log_level::warn:
return EVENTLOG_WARNING_TYPE; return EVENTLOG_WARNING_TYPE;
case level::err: case log_level::err:
case level::critical: case log_level::critical:
case level::off: case log_level::off:
return EVENTLOG_ERROR_TYPE; return EVENTLOG_ERROR_TYPE;
default: default:

View File

@ -24,14 +24,14 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
set_color_mode_impl(mode); set_color_mode_impl(mode);
// set level colors // set level colors
colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white colors_[log_level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
colors_[level::debug] = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan colors_[log_level::debug] = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
colors_[level::info] = FOREGROUND_GREEN; // green colors_[log_level::info] = FOREGROUND_GREEN; // green
colors_[level::warn] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow colors_[spdlog::log_level::warn] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
colors_[level::err] = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red colors_[log_level::err] = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
colors_[level::critical] = colors_[log_level::critical] =
BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background
colors_[level::off] = 0; colors_[log_level::off] = 0;
} }
template<typename ConsoleMutex> template<typename ConsoleMutex>
@ -42,7 +42,7 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::~wincolor_sink()
// change the color for the given level // change the color for the given level
template<typename ConsoleMutex> template<typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color(level::level_enum level, std::uint16_t color) void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color(log_level level, std::uint16_t color)
{ {
std::lock_guard<mutex_t> lock(mutex_); std::lock_guard<mutex_t> lock(mutex_);
colors_[static_cast<size_t>(level)] = color; colors_[static_cast<size_t>(level)] = color;

View File

@ -31,7 +31,7 @@ public:
wincolor_sink &operator=(const wincolor_sink &other) = delete; wincolor_sink &operator=(const wincolor_sink &other) = delete;
// change the color for the given level // change the color for the given level
void set_color(level::level_enum level, std::uint16_t color); void set_color(log_level level, std::uint16_t color);
void log(const details::log_msg &msg) final override; void log(const details::log_msg &msg) final override;
void flush() final override; void flush() final override;
void set_pattern(const std::string &pattern) override final; void set_pattern(const std::string &pattern) override final;
@ -44,7 +44,7 @@ protected:
mutex_t &mutex_; mutex_t &mutex_;
bool should_do_colors_; bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
std::array<std::uint16_t, level::n_levels> colors_; std::array<std::uint16_t, log_level::n_levels> colors_;
// set foreground color and return the orig console attributes (for resetting later) // set foreground color and return the orig console attributes (for resetting later)
std::uint16_t set_foreground_color_(std::uint16_t attribs); std::uint16_t set_foreground_color_(std::uint16_t attribs);

View File

@ -32,22 +32,22 @@ 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))); set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
} }
SPDLOG_INLINE level::level_enum get_level() SPDLOG_INLINE log_level get_level()
{ {
return default_logger_raw()->level(); return default_logger_raw()->level();
} }
SPDLOG_INLINE bool should_log(level::level_enum log_level) SPDLOG_INLINE bool should_log(log_level log_level)
{ {
return default_logger_raw()->should_log(log_level); return default_logger_raw()->should_log(log_level);
} }
SPDLOG_INLINE void set_level(level::level_enum log_level) SPDLOG_INLINE void set_level(log_level log_level)
{ {
details::registry::instance().set_level(log_level); details::registry::instance().set_level(log_level);
} }
SPDLOG_INLINE void flush_on(level::level_enum log_level) SPDLOG_INLINE void flush_on(log_level log_level)
{ {
details::registry::instance().flush_on(log_level); details::registry::instance().flush_on(log_level);
} }

View File

@ -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); SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
// Get global logging level // Get global logging level
SPDLOG_API level::level_enum get_level(); SPDLOG_API log_level get_level();
// Set global logging level // Set global logging level
SPDLOG_API void set_level(level::level_enum log_level); SPDLOG_API void set_level(log_level log_level);
// Determine whether the default logger should log messages with a certain level // Determine whether the default logger should log messages with a certain level
SPDLOG_API bool should_log(level::level_enum lvl); SPDLOG_API bool should_log(log_level lvl);
// Set global flush level // Set global flush level
SPDLOG_API void flush_on(level::level_enum log_level); SPDLOG_API void flush_on(log_level log_level);
// Start/Restart a periodic flusher thread // Start/Restart a periodic flusher thread
// Warning: Use only if all your loggers are thread safe! // 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); SPDLOG_API void apply_logger_env_levels(std::shared_ptr<logger> logger);
template<typename... Args> template<typename... Args>
inline void log(source_loc source, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) inline void log(source_loc source, log_level lvl, format_string_t<Args...> fmt, Args &&...args)
{ {
default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void log(level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) inline void log(log_level lvl, format_string_t<Args...> fmt, Args &&...args)
{ {
default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
} }
template<typename S, typename = is_convertible_to_sv<S>, typename... Args> template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
inline void log(source_loc loc, level::level_enum lvl, S fmt, Args &&...args) inline void log(source_loc loc, log_level lvl, S fmt, Args &&...args)
{ {
default_logger_raw()->log(loc, lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(loc, lvl, fmt, std::forward<Args>(args)...);
} }
template<typename S, typename = is_convertible_to_sv<S>, typename... Args> template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
inline void log(level::level_enum lvl, S fmt, Args &&...args) inline void log(log_level lvl, S fmt, Args &&...args)
{ {
default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
} }
@ -159,135 +159,135 @@ inline void log(level::level_enum lvl, S fmt, Args &&...args)
template<typename... Args> template<typename... Args>
inline void trace(loc_with_fmt fmt, Args &&...args) inline void trace(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void debug(loc_with_fmt fmt, Args &&...args) inline void debug(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void info(loc_with_fmt fmt, Args &&...args) inline void info(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::info, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void warn(loc_with_fmt fmt, Args &&...args) inline void warn(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::warn, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, spdlog::log_level::warn, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void error(loc_with_fmt fmt, Args &&...args) inline void error(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::err, fmt.fmt_string, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void critical(loc_with_fmt fmt, Args &&...args) inline void critical(loc_with_fmt fmt, Args &&...args)
{ {
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(args)...); log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward<Args>(args)...);
} }
// log functions with no format string, just string // log functions with no format string, just string
inline void trace(string_view_t msg, source_loc loc = source_loc::current()) inline void trace(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::trace, msg); log(loc, log_level::trace, msg);
} }
inline void debug(string_view_t msg, source_loc loc = source_loc::current()) inline void debug(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::debug, msg); log(loc, log_level::debug, msg);
} }
inline void info(string_view_t msg, source_loc loc = source_loc::current()) inline void info(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::info, msg); log(loc, log_level::info, msg);
} }
inline void warn(string_view_t msg, source_loc loc = source_loc::current()) inline void warn(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::warn, msg); log(loc, spdlog::log_level::warn, msg);
} }
inline void error(string_view_t msg, source_loc loc = source_loc::current()) inline void error(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::err, msg); log(loc, log_level::err, msg);
} }
inline void critical(string_view_t msg, source_loc loc = source_loc::current()) inline void critical(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::critical, msg); log(loc, log_level::critical, msg);
} }
#else #else
template<typename... Args> template<typename... Args>
inline void trace(format_string_t<Args...> fmt, Args &&...args) inline void trace(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::trace, fmt, std::forward<Args>(args)...); log(log_level::trace, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void debug(format_string_t<Args...> fmt, Args &&...args) inline void debug(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::debug, fmt, std::forward<Args>(args)...); log(log_level::debug, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void info(format_string_t<Args...> fmt, Args &&...args) inline void info(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::info, fmt, std::forward<Args>(args)...); log(log_level::info, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void warn(format_string_t<Args...> fmt, Args &&...args) inline void warn(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::warn, fmt, std::forward<Args>(args)...); log(log_level::warn, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void error(format_string_t<Args...> fmt, Args &&...args) inline void error(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::err, fmt, std::forward<Args>(args)...); log(log_level::err, fmt, std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
inline void critical(format_string_t<Args...> fmt, Args &&...args) inline void critical(format_string_t<Args...> fmt, Args &&...args)
{ {
log(level::critical, fmt, std::forward<Args>(args)...); log(log_level::critical, fmt, std::forward<Args>(args)...);
} }
// log functions with no format string, just string // log functions with no format string, just string
inline void trace(string_view_t msg) inline void trace(string_view_t msg)
{ {
log(level::trace, msg); log(log_level::trace, msg);
} }
inline void debug(string_view_t msg) inline void debug(string_view_t msg)
{ {
log(level::debug, msg); log(log_level::debug, msg);
} }
inline void info(string_view_t msg) inline void info(string_view_t msg)
{ {
log(level::info, msg); log(log_level::info, msg);
} }
inline void warn(string_view_t msg) inline void warn(string_view_t msg)
{ {
log(level::warn, msg); log(log_level::warn, msg);
} }
inline void error(string_view_t msg) inline void error(string_view_t msg)
{ {
log(level::err, msg); log(log_level::err, msg);
} }
inline void critical(string_view_t msg) inline void critical(string_view_t msg)
{ {
log(level::critical, msg); log(log_level::critical, msg);
} }
#endif #endif
@ -314,7 +314,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) # define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::trace, __VA_ARGS__)
# define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 # define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
@ -322,7 +322,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) # define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::debug, __VA_ARGS__)
# define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 # define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
@ -330,7 +330,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) # define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::info, __VA_ARGS__)
# define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_INFO(logger, ...) (void)0 # define SPDLOG_LOGGER_INFO(logger, ...) (void)0
@ -338,7 +338,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) # define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::warn, __VA_ARGS__)
# define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_WARN(logger, ...) (void)0 # define SPDLOG_LOGGER_WARN(logger, ...) (void)0
@ -346,7 +346,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) # define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::err, __VA_ARGS__)
# define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 # define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
@ -354,7 +354,7 @@ inline void critical(string_view_t msg)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) # define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::critical, __VA_ARGS__)
# define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
# define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 # define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0

View File

@ -19,9 +19,9 @@ TEST_CASE("env", "[cfg]")
setenv("SPDLOG_LEVEL", "l1=warn", 1); setenv("SPDLOG_LEVEL", "l1=warn", 1);
#endif #endif
load_env_levels(); load_env_levels();
REQUIRE(l1->level() == spdlog::level::warn); REQUIRE(l1->level() == spdlog::log_level::warn);
spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default")); spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default"));
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }
TEST_CASE("argv1", "[cfg]") TEST_CASE("argv1", "[cfg]")
@ -30,8 +30,8 @@ TEST_CASE("argv1", "[cfg]")
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"};
load_argv_levels(2, argv); load_argv_levels(2, argv);
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn); REQUIRE(l1->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }
TEST_CASE("argv2", "[cfg]") TEST_CASE("argv2", "[cfg]")
@ -40,60 +40,60 @@ TEST_CASE("argv2", "[cfg]")
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"};
load_argv_levels(2, argv); load_argv_levels(2, argv);
auto l1 = spdlog::create<test_sink_st>("l1"); auto l1 = spdlog::create<test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn); REQUIRE(l1->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace);
} }
TEST_CASE("argv3", "[cfg]") TEST_CASE("argv3", "[cfg]")
{ {
spdlog::set_level(spdlog::level::trace); spdlog::set_level(spdlog::log_level::trace);
spdlog::drop("l1"); spdlog::drop("l1");
const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk_name=warn"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk_name=warn"};
load_argv_levels(2, argv); load_argv_levels(2, argv);
auto l1 = spdlog::create<test_sink_st>("l1"); auto l1 = spdlog::create<test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::trace); REQUIRE(l1->level() == spdlog::log_level::trace);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace);
} }
TEST_CASE("argv4", "[cfg]") TEST_CASE("argv4", "[cfg]")
{ {
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
spdlog::drop("l1"); spdlog::drop("l1");
const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"};
load_argv_levels(2, argv); load_argv_levels(2, argv);
auto l1 = spdlog::create<test_sink_st>("l1"); auto l1 = spdlog::create<test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::info); REQUIRE(l1->level() == spdlog::log_level::info);
} }
TEST_CASE("argv5", "[cfg]") TEST_CASE("argv5", "[cfg]")
{ {
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
spdlog::drop("l1"); spdlog::drop("l1");
const char *argv[] = {"ignore", "ignore", "SPDLOG_LEVEL=l1=warn,trace"}; const char *argv[] = {"ignore", "ignore", "SPDLOG_LEVEL=l1=warn,trace"};
load_argv_levels(3, argv); load_argv_levels(3, argv);
auto l1 = spdlog::create<test_sink_st>("l1"); auto l1 = spdlog::create<test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn); REQUIRE(l1->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
} }
TEST_CASE("argv6", "[cfg]") TEST_CASE("argv6", "[cfg]")
{ {
spdlog::set_level(spdlog::level::err); spdlog::set_level(spdlog::log_level::err);
const char *argv[] = {""}; const char *argv[] = {""};
load_argv_levels(1, argv); load_argv_levels(1, argv);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::err);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
} }
TEST_CASE("argv7", "[cfg]") TEST_CASE("argv7", "[cfg]")
{ {
spdlog::set_level(spdlog::level::err); spdlog::set_level(spdlog::log_level::err);
const char *argv[] = {""}; const char *argv[] = {""};
load_argv_levels(0, argv); load_argv_levels(0, argv);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::err);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
} }
TEST_CASE("level-not-set-test1", "[cfg]") TEST_CASE("level-not-set-test1", "[cfg]")
@ -102,9 +102,9 @@ TEST_CASE("level-not-set-test1", "[cfg]")
const char *argv[] = {"ignore", ""}; const char *argv[] = {"ignore", ""};
load_argv_levels(2, argv); load_argv_levels(2, argv);
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
l1->set_level(spdlog::level::trace); l1->set_level(spdlog::log_level::trace);
REQUIRE(l1->level() == spdlog::level::trace); REQUIRE(l1->level() == spdlog::log_level::trace);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }
TEST_CASE("level-not-set-test2", "[cfg]") TEST_CASE("level-not-set-test2", "[cfg]")
@ -114,15 +114,15 @@ TEST_CASE("level-not-set-test2", "[cfg]")
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=trace"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=trace"};
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
l1->set_level(spdlog::level::warn); l1->set_level(spdlog::log_level::warn);
auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2"); auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2");
l2->set_level(spdlog::level::warn); l2->set_level(spdlog::log_level::warn);
load_argv_levels(2, argv); load_argv_levels(2, argv);
REQUIRE(l1->level() == spdlog::level::trace); REQUIRE(l1->level() == spdlog::log_level::trace);
REQUIRE(l2->level() == spdlog::level::warn); REQUIRE(l2->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }
TEST_CASE("level-not-set-test3", "[cfg]") TEST_CASE("level-not-set-test3", "[cfg]")
@ -136,9 +136,9 @@ TEST_CASE("level-not-set-test3", "[cfg]")
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2"); auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2");
REQUIRE(l1->level() == spdlog::level::trace); REQUIRE(l1->level() == spdlog::log_level::trace);
REQUIRE(l2->level() == spdlog::level::info); REQUIRE(l2->level() == spdlog::log_level::info);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }
TEST_CASE("level-not-set-test4", "[cfg]") TEST_CASE("level-not-set-test4", "[cfg]")
@ -152,9 +152,9 @@ TEST_CASE("level-not-set-test4", "[cfg]")
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2"); auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2");
REQUIRE(l1->level() == spdlog::level::trace); REQUIRE(l1->level() == spdlog::log_level::trace);
REQUIRE(l2->level() == spdlog::level::warn); REQUIRE(l2->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::warn); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::warn);
} }
TEST_CASE("level-not-set-test5", "[cfg]") TEST_CASE("level-not-set-test5", "[cfg]")
@ -168,9 +168,9 @@ TEST_CASE("level-not-set-test5", "[cfg]")
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1"); auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2"); auto l2 = spdlog::create<spdlog::sinks::test_sink_st>("l2");
REQUIRE(l1->level() == spdlog::level::warn); REQUIRE(l1->level() == spdlog::log_level::warn);
REQUIRE(l2->level() == spdlog::level::warn); REQUIRE(l2->level() == spdlog::log_level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::warn); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::warn);
} }
TEST_CASE("restore-to-default", "[cfg]") TEST_CASE("restore-to-default", "[cfg]")
@ -179,5 +179,5 @@ TEST_CASE("restore-to-default", "[cfg]")
spdlog::drop("l2"); spdlog::drop("l2");
const char *argv[] = {"ignore", "SPDLOG_LEVEL=info"}; const char *argv[] = {"ignore", "SPDLOG_LEVEL=info"};
load_argv_levels(2, argv); load_argv_levels(2, argv);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info); REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info);
} }

View File

@ -137,7 +137,7 @@ TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink
static spdlog::details::log_msg create_msg(std::chrono::seconds offset) static spdlog::details::log_msg create_msg(std::chrono::seconds offset)
{ {
using spdlog::log_clock; using spdlog::log_clock;
spdlog::details::log_msg msg{"test", spdlog::level::info, "Hello Message"}; spdlog::details::log_msg msg{"test", spdlog::log_level::info, "Hello Message"};
msg.time = log_clock::now() + offset; msg.time = log_clock::now() + offset;
return msg; return msg;
} }

View File

@ -13,7 +13,7 @@ TEST_CASE("dup_filter_test1", "[dup_filter_sink]")
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
} }
REQUIRE(test_sink->msg_counter() == 1); REQUIRE(test_sink->msg_counter() == 1);
@ -30,7 +30,7 @@ TEST_CASE("dup_filter_test2", "[dup_filter_sink]")
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
std::this_thread::sleep_for(std::chrono::milliseconds(5)); std::this_thread::sleep_for(std::chrono::milliseconds(5));
} }
@ -48,8 +48,8 @@ TEST_CASE("dup_filter_test3", "[dup_filter_sink]")
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message2"});
} }
REQUIRE(test_sink->msg_counter() == 20); REQUIRE(test_sink->msg_counter() == 20);
@ -64,9 +64,9 @@ TEST_CASE("dup_filter_test4", "[dup_filter_sink]")
auto test_sink = std::make_shared<test_sink_mt>(); auto test_sink = std::make_shared<test_sink_mt>();
dup_sink.add_sink(test_sink); dup_sink.add_sink(test_sink);
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message"});
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message"});
REQUIRE(test_sink->msg_counter() == 2); REQUIRE(test_sink->msg_counter() == 2);
} }
@ -80,10 +80,10 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
test_sink->set_pattern("%v"); test_sink->set_pattern("%v");
dup_sink.add_sink(test_sink); dup_sink.add_sink(test_sink);
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"});
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"}); dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message2"});
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2 REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages.."); REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages..");

View File

@ -45,7 +45,7 @@ TEST_CASE("custom_error_handler", "[errors]")
prepare_logdir(); prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG); spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename, true); auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
logger->flush_on(spdlog::level::info); logger->flush_on(spdlog::log_level::info);
logger->set_error_handler([=](const std::string &) { throw custom_ex(); }); logger->set_error_handler([=](const std::string &) { throw custom_ex(); });
logger->info("Good message #1"); logger->info("Good message #1");

View File

@ -56,7 +56,7 @@ TEST_CASE("eventlog", "[eventlog]")
auto test_sink = std::make_shared<sinks::win_eventlog_sink_mt>(TEST_SOURCE); auto test_sink = std::make_shared<sinks::win_eventlog_sink_mt>(TEST_SOURCE);
spdlog::logger test_logger("eventlog", test_sink); spdlog::logger test_logger("eventlog", test_sink);
test_logger.set_level(level::trace); test_logger.set_level(log_level::trace);
test_sink->set_pattern("%v"); test_sink->set_pattern("%v");

View File

@ -30,8 +30,8 @@ TEST_CASE("flush_on", "[flush_on]")
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename); auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
logger->set_pattern("%v"); logger->set_pattern("%v");
logger->set_level(spdlog::level::trace); logger->set_level(spdlog::log_level::trace);
logger->flush_on(spdlog::level::info); logger->flush_on(spdlog::log_level::info);
logger->trace("Should not be flushed"); logger->trace("Should not be flushed");
REQUIRE(count_lines(SIMPLE_LOG) == 0); REQUIRE(count_lines(SIMPLE_LOG) == 0);

View File

@ -18,7 +18,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]")
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename); auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
logger->set_pattern("%v"); logger->set_pattern("%v");
logger->set_level(spdlog::level::trace); logger->set_level(spdlog::log_level::trace);
SPDLOG_LOGGER_TRACE(logger, "Test message 1"); SPDLOG_LOGGER_TRACE(logger, "Test message 1");
SPDLOG_LOGGER_DEBUG(logger, "Test message 2"); SPDLOG_LOGGER_DEBUG(logger, "Test message 2");

View File

@ -2,7 +2,7 @@
#include "test_sink.h" #include "test_sink.h"
template<class T> template<class T>
std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info) std::string log_info(const T &what, spdlog::log_level logger_level = spdlog::log_level::info)
{ {
std::ostringstream oss; std::ostringstream oss;
@ -29,46 +29,46 @@ TEST_CASE("basic_logging ", "[basic_logging]")
TEST_CASE("log_levels", "[log_levels]") TEST_CASE("log_levels", "[log_levels]")
{ {
REQUIRE(log_info("Hello", spdlog::level::err).empty()); REQUIRE(log_info("Hello", spdlog::log_level::err).empty());
REQUIRE(log_info("Hello", spdlog::level::critical).empty()); REQUIRE(log_info("Hello", spdlog::log_level::critical).empty());
REQUIRE(log_info("Hello", spdlog::level::info) == "Hello"); REQUIRE(log_info("Hello", spdlog::log_level::info) == "Hello");
REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello"); REQUIRE(log_info("Hello", spdlog::log_level::debug) == "Hello");
REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello"); REQUIRE(log_info("Hello", spdlog::log_level::trace) == "Hello");
} }
TEST_CASE("level_to_string_view", "[convert_to_string_view]") TEST_CASE("level_to_string_view", "[convert_to_string_view]")
{ {
REQUIRE(spdlog::level::to_string_view(spdlog::level::trace) == "trace"); REQUIRE(spdlog::to_string_view(spdlog::log_level::trace) == "trace");
REQUIRE(spdlog::level::to_string_view(spdlog::level::debug) == "debug"); REQUIRE(spdlog::to_string_view(spdlog::log_level::debug) == "debug");
REQUIRE(spdlog::level::to_string_view(spdlog::level::info) == "info"); REQUIRE(spdlog::to_string_view(spdlog::log_level::info) == "info");
REQUIRE(spdlog::level::to_string_view(spdlog::level::warn) == "warning"); REQUIRE(spdlog::to_string_view(spdlog::log_level::warn) == "warning");
REQUIRE(spdlog::level::to_string_view(spdlog::level::err) == "error"); REQUIRE(spdlog::to_string_view(spdlog::log_level::err) == "error");
REQUIRE(spdlog::level::to_string_view(spdlog::level::critical) == "critical"); REQUIRE(spdlog::to_string_view(spdlog::log_level::critical) == "critical");
REQUIRE(spdlog::level::to_string_view(spdlog::level::off) == "off"); REQUIRE(spdlog::to_string_view(spdlog::log_level::off) == "off");
} }
TEST_CASE("to_short_c_str", "[convert_to_short_c_str]") TEST_CASE("to_short_c_str", "[convert_to_short_c_str]")
{ {
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::trace)) == "T"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::trace)) == "T");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::debug)) == "D"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::debug)) == "D");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::info)) == "I"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::info)) == "I");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::warn)) == "W"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::warn)) == "W");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::err)) == "E"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::err)) == "E");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::critical)) == "C"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::critical)) == "C");
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::off)) == "O"); REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::off)) == "O");
} }
TEST_CASE("to_level_enum", "[convert_to_level_enum]") TEST_CASE("to_level_enum", "[convert_to_level_enum]")
{ {
REQUIRE(spdlog::level::from_str("trace") == spdlog::level::trace); REQUIRE(spdlog::level_from_str("trace") == spdlog::log_level::trace);
REQUIRE(spdlog::level::from_str("debug") == spdlog::level::debug); REQUIRE(spdlog::level_from_str("debug") == spdlog::log_level::debug);
REQUIRE(spdlog::level::from_str("info") == spdlog::level::info); REQUIRE(spdlog::level_from_str("info") == spdlog::log_level::info);
REQUIRE(spdlog::level::from_str("warning") == spdlog::level::warn); REQUIRE(spdlog::level_from_str("warning") == spdlog::log_level::warn);
REQUIRE(spdlog::level::from_str("warn") == spdlog::level::warn); REQUIRE(spdlog::level_from_str("warn") == spdlog::log_level::warn);
REQUIRE(spdlog::level::from_str("error") == spdlog::level::err); REQUIRE(spdlog::level_from_str("error") == spdlog::log_level::err);
REQUIRE(spdlog::level::from_str("critical") == spdlog::level::critical); REQUIRE(spdlog::level_from_str("critical") == spdlog::log_level::critical);
REQUIRE(spdlog::level::from_str("off") == spdlog::level::off); REQUIRE(spdlog::level_from_str("off") == spdlog::log_level::off);
REQUIRE(spdlog::level::from_str("null") == spdlog::level::off); REQUIRE(spdlog::level_from_str("null") == spdlog::log_level::off);
} }
TEST_CASE("periodic flush", "[periodic_flush]") TEST_CASE("periodic flush", "[periodic_flush]")
@ -140,7 +140,7 @@ TEST_CASE("default logger API", "[default logger]")
spdlog::set_default_logger(std::make_shared<spdlog::logger>("oss", oss_sink)); spdlog::set_default_logger(std::make_shared<spdlog::logger>("oss", oss_sink));
spdlog::set_pattern("*** %v"); spdlog::set_pattern("*** %v");
spdlog::default_logger()->set_level(spdlog::level::trace); spdlog::default_logger()->set_level(spdlog::log_level::trace);
spdlog::trace("hello trace"); spdlog::trace("hello trace");
REQUIRE(oss.str() == "*** hello trace" + std::string(spdlog::details::os::default_eol)); REQUIRE(oss.str() == "*** hello trace" + std::string(spdlog::details::os::default_eol));
@ -161,7 +161,7 @@ TEST_CASE("default logger API", "[default logger]")
REQUIRE(oss.str() == "*** some string" + std::string(spdlog::details::os::default_eol)); REQUIRE(oss.str() == "*** some string" + std::string(spdlog::details::os::default_eol));
oss.str(""); oss.str("");
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
spdlog::debug("should not be logged"); spdlog::debug("should not be logged");
REQUIRE(oss.str().empty()); REQUIRE(oss.str().empty());
spdlog::drop_all(); spdlog::drop_all();

View File

@ -11,7 +11,7 @@ static std::string log_to_str(const std::string &msg, const Args &...args)
std::ostringstream oss; std::ostringstream oss;
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
spdlog::logger oss_logger("pattern_tester", oss_sink); spdlog::logger oss_logger("pattern_tester", oss_sink);
oss_logger.set_level(spdlog::level::info); oss_logger.set_level(spdlog::log_level::info);
oss_logger.set_formatter(std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...))); oss_logger.set_formatter(std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
@ -68,7 +68,7 @@ TEST_CASE("color range test1", "[pattern_formatter]")
spdlog::fmt_lib::format_to(std::back_inserter(buf), "Hello"); spdlog::fmt_lib::format_to(std::back_inserter(buf), "Hello");
memory_buf_t formatted; memory_buf_t formatted;
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size())); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, spdlog::string_view_t(buf.data(), buf.size()));
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0); REQUIRE(msg.color_range_start == 0);
REQUIRE(msg.color_range_end == 5); REQUIRE(msg.color_range_end == 5);
@ -79,7 +79,7 @@ TEST_CASE("color range test2", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n"); auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, ""); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "");
memory_buf_t formatted; memory_buf_t formatted;
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0); REQUIRE(msg.color_range_start == 0);
@ -91,7 +91,7 @@ TEST_CASE("color range test3", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$"); auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$");
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored");
memory_buf_t formatted; memory_buf_t formatted;
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0); REQUIRE(msg.color_range_start == 0);
@ -102,7 +102,7 @@ TEST_CASE("color range test4", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("XX%^YYY%$", spdlog::pattern_time_type::local, "\n"); auto formatter = std::make_shared<spdlog::pattern_formatter>("XX%^YYY%$", spdlog::pattern_time_type::local, "\n");
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored");
memory_buf_t formatted; memory_buf_t formatted;
formatter->format(msg, formatted); formatter->format(msg, formatted);
@ -115,7 +115,7 @@ TEST_CASE("color range test5", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^"); auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^");
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored");
memory_buf_t formatted; memory_buf_t formatted;
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 2); REQUIRE(msg.color_range_start == 2);
@ -126,7 +126,7 @@ TEST_CASE("color range test6", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$"); auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$");
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored");
memory_buf_t formatted; memory_buf_t formatted;
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0); REQUIRE(msg.color_range_start == 0);
@ -236,11 +236,11 @@ TEST_CASE("padding_truncate_funcname", "[pattern_formatter]")
auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern)); auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern));
test_sink.set_formatter(std::move(formatter)); test_sink.set_formatter(std::move(formatter));
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::log_level::info, "message"};
test_sink.log(msg1); test_sink.log(msg1);
REQUIRE(test_sink.lines()[0] == "message [ func]"); REQUIRE(test_sink.lines()[0] == "message [ func]");
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info, "message"}; spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::log_level::info, "message"};
test_sink.log(msg2); test_sink.log(msg2);
REQUIRE(test_sink.lines()[1] == "message [funct]"); REQUIRE(test_sink.lines()[1] == "message [funct]");
} }
@ -253,11 +253,11 @@ TEST_CASE("padding_funcname", "[pattern_formatter]")
auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern)); auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern));
test_sink.set_formatter(std::move(formatter)); test_sink.set_formatter(std::move(formatter));
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::log_level::info, "message"};
test_sink.log(msg1); test_sink.log(msg1);
REQUIRE(test_sink.lines()[0] == "message [ func]"); REQUIRE(test_sink.lines()[0] == "message [ func]");
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger", spdlog::level::info, "message"}; spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger", spdlog::log_level::info, "message"};
test_sink.log(msg2); test_sink.log(msg2);
REQUIRE(test_sink.lines()[1] == "message [func567890123]"); REQUIRE(test_sink.lines()[1] == "message [func567890123]");
} }
@ -267,7 +267,7 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]")
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>(); auto formatter_1 = std::make_shared<spdlog::pattern_formatter>();
auto formatter_2 = formatter_1->clone(); auto formatter_2 = formatter_1->clone();
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message");
memory_buf_t formatted_1; memory_buf_t formatted_1;
memory_buf_t formatted_2; memory_buf_t formatted_2;
@ -282,7 +282,7 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]")
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%+"); auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%+");
auto formatter_2 = formatter_1->clone(); auto formatter_2 = formatter_1->clone();
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message");
memory_buf_t formatted_1; memory_buf_t formatted_1;
memory_buf_t formatted_2; memory_buf_t formatted_2;
@ -297,7 +297,7 @@ TEST_CASE("clone-formatter", "[pattern_formatter]")
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v"); auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v");
auto formatter_2 = formatter_1->clone(); auto formatter_2 = formatter_1->clone();
std::string logger_name = "test"; std::string logger_name = "test";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message");
memory_buf_t formatted_1; memory_buf_t formatted_1;
memory_buf_t formatted_2; memory_buf_t formatted_2;
@ -313,7 +313,7 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n"); auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n");
auto formatter_2 = formatter_1->clone(); auto formatter_2 = formatter_1->clone();
std::string logger_name = "test2"; std::string logger_name = "test2";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message");
memory_buf_t formatted_1; memory_buf_t formatted_1;
memory_buf_t formatted_2; memory_buf_t formatted_2;
@ -364,7 +364,7 @@ TEST_CASE("clone-custom_formatter", "[pattern_formatter]")
formatter_1->add_flag<custom_test_flag>('t', "custom_output").set_pattern("[%n] [%t] %v"); formatter_1->add_flag<custom_test_flag>('t', "custom_output").set_pattern("[%n] [%t] %v");
auto formatter_2 = formatter_1->clone(); auto formatter_2 = formatter_1->clone();
std::string logger_name = "logger-name"; std::string logger_name = "logger-name";
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message");
memory_buf_t formatted_1; memory_buf_t formatted_1;
memory_buf_t formatted_2; memory_buf_t formatted_2;
@ -393,7 +393,7 @@ TEST_CASE("short filename formatter-1", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
std::string logger_name = "logger-name"; std::string logger_name = "logger-name";
spdlog::source_loc source_loc{test_path, 123, "some_func()"}; spdlog::source_loc source_loc{test_path, 123, "some_func()"};
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello");
formatter.format(msg, formatted); formatter.format(msg, formatted);
REQUIRE(to_string_view(formatted) == "myfile.cpp"); REQUIRE(to_string_view(formatted) == "myfile.cpp");
@ -405,7 +405,7 @@ TEST_CASE("short filename formatter-2", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
std::string logger_name = "logger-name"; std::string logger_name = "logger-name";
spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"}; spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"};
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello");
formatter.format(msg, formatted); formatter.format(msg, formatted);
REQUIRE(to_string_view(formatted) == "myfile.cpp:123"); REQUIRE(to_string_view(formatted) == "myfile.cpp:123");
@ -417,7 +417,7 @@ TEST_CASE("short filename formatter-3", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
std::string logger_name = "logger-name"; std::string logger_name = "logger-name";
spdlog::source_loc source_loc{"", 123, "some_func()"}; spdlog::source_loc source_loc{"", 123, "some_func()"};
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello");
formatter.format(msg, formatted); formatter.format(msg, formatted);
REQUIRE(to_string_view(formatted) == " Hello"); REQUIRE(to_string_view(formatted) == " Hello");
@ -429,7 +429,7 @@ TEST_CASE("full filename formatter", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
std::string logger_name = "logger-name"; std::string logger_name = "logger-name";
spdlog::source_loc source_loc{test_path, 123, "some_func()"}; spdlog::source_loc source_loc{test_path, 123, "some_func()"};
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello");
formatter.format(msg, formatted); formatter.format(msg, formatted);
REQUIRE(to_string_view(formatted) == test_path); REQUIRE(to_string_view(formatted) == test_path);
@ -442,7 +442,7 @@ TEST_CASE("custom flags", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message");
formatter->format(msg, formatted); formatter->format(msg, formatted);
auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}", spdlog::details::os::default_eol); auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}", spdlog::details::os::default_eol);
@ -456,7 +456,7 @@ TEST_CASE("custom flags-padding", "[pattern_formatter]")
memory_buf_t formatted; memory_buf_t formatted;
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message");
formatter->format(msg, formatted); formatter->format(msg, formatted);
auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [ custom2] some message{}", spdlog::details::os::default_eol); auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [ custom2] some message{}", spdlog::details::os::default_eol);
@ -469,7 +469,7 @@ TEST_CASE("custom flags-exception", "[pattern_formatter]")
formatter->add_flag<custom_test_flag>('t', "throw_me").add_flag<custom_test_flag>('u', "custom2").set_pattern("[%n] [%t] [%u] %v"); formatter->add_flag<custom_test_flag>('t', "throw_me").add_flag<custom_test_flag>('u', "custom2").set_pattern("[%n] [%t] [%u] %v");
memory_buf_t formatted; memory_buf_t formatted;
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message");
CHECK_THROWS_AS(formatter->format(msg, formatted), spdlog::spdlog_ex); CHECK_THROWS_AS(formatter->format(msg, formatted), spdlog::spdlog_ex);
} }
@ -480,7 +480,7 @@ TEST_CASE("override need_localtime", "[pattern_formatter]")
{ {
memory_buf_t formatted; memory_buf_t formatted;
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message");
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(to_string_view(formatted) == "0:00AM> some message\n"); REQUIRE(to_string_view(formatted) == "0:00AM> some message\n");
} }
@ -494,7 +494,7 @@ TEST_CASE("override need_localtime", "[pattern_formatter]")
<< "> some message\n"; << "> some message\n";
memory_buf_t formatted; memory_buf_t formatted;
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message");
formatter->format(msg, formatted); formatter->format(msg, formatted);
REQUIRE(to_string_view(formatted) == oss.str()); REQUIRE(to_string_view(formatted) == oss.str());
} }

View File

@ -99,7 +99,7 @@ TEST_CASE("set_default_logger(nullptr)", "[registry]")
TEST_CASE("disable automatic registration", "[registry]") TEST_CASE("disable automatic registration", "[registry]")
{ {
// set some global parameters // set some global parameters
spdlog::level::level_enum log_level = spdlog::level::level_enum::warn; spdlog::log_level log_level = spdlog::log_level::warn;
spdlog::set_level(log_level); spdlog::set_level(log_level);
// but disable automatic registration // but disable automatic registration
spdlog::set_automatic_registration(false); spdlog::set_automatic_registration(false);
@ -111,6 +111,6 @@ TEST_CASE("disable automatic registration", "[registry]")
// but make sure they are still initialized according to global defaults // but make sure they are still initialized according to global defaults
REQUIRE(logger1->level() == log_level); REQUIRE(logger1->level() == log_level);
REQUIRE(logger2->level() == log_level); REQUIRE(logger2->level() == log_level);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::log_level::info);
spdlog::set_automatic_registration(true); spdlog::set_automatic_registration(true);
} }

View File

@ -8,7 +8,7 @@ TEST_CASE("stdout_st", "[stdout]")
{ {
auto l = spdlog::stdout_logger_st("test"); auto l = spdlog::stdout_logger_st("test");
l->set_pattern("%+"); l->set_pattern("%+");
l->set_level(spdlog::level::trace); l->set_level(spdlog::log_level::trace);
l->trace("Test stdout_st"); l->trace("Test stdout_st");
spdlog::drop_all(); spdlog::drop_all();
} }
@ -17,7 +17,7 @@ TEST_CASE("stdout_mt", "[stdout]")
{ {
auto l = spdlog::stdout_logger_mt("test"); auto l = spdlog::stdout_logger_mt("test");
l->set_pattern("%+"); l->set_pattern("%+");
l->set_level(spdlog::level::debug); l->set_level(spdlog::log_level::debug);
l->debug("Test stdout_mt"); l->debug("Test stdout_mt");
spdlog::drop_all(); spdlog::drop_all();
} }
@ -54,7 +54,7 @@ TEST_CASE("stdout_color_mt", "[stdout]")
{ {
auto l = spdlog::stdout_color_mt("test"); auto l = spdlog::stdout_color_mt("test");
l->set_pattern("%+"); l->set_pattern("%+");
l->set_level(spdlog::level::trace); l->set_level(spdlog::log_level::trace);
l->trace("Test stdout_color_mt"); l->trace("Test stdout_color_mt");
spdlog::drop_all(); spdlog::drop_all();
} }
@ -63,7 +63,7 @@ TEST_CASE("stderr_color_st", "[stderr]")
{ {
auto l = spdlog::stderr_color_st("test"); auto l = spdlog::stderr_color_st("test");
l->set_pattern("%+"); l->set_pattern("%+");
l->set_level(spdlog::level::debug); l->set_level(spdlog::log_level::debug);
l->debug("Test stderr_color_st"); l->debug("Test stderr_color_st");
spdlog::drop_all(); spdlog::drop_all();
} }

View File

@ -5,7 +5,7 @@ TEST_CASE("systemd", "[all]")
{ {
auto systemd_sink = std::make_shared<spdlog::sinks::systemd_sink_st>(); auto systemd_sink = std::make_shared<spdlog::sinks::systemd_sink_st>();
spdlog::logger logger("spdlog_systemd_test", systemd_sink); spdlog::logger logger("spdlog_systemd_test", systemd_sink);
logger.set_level(spdlog::level::trace); logger.set_level(spdlog::log_level::trace);
logger.trace("test spdlog trace"); logger.trace("test spdlog trace");
logger.debug("test spdlog debug"); logger.debug("test spdlog debug");
SPDLOG_LOGGER_INFO((&logger), "test spdlog info"); SPDLOG_LOGGER_INFO((&logger), "test spdlog info");

View File

@ -15,15 +15,15 @@ TEST_CASE("time_point1", "[time_point log_msg]")
test_sink->set_delay(std::chrono::milliseconds(10)); test_sink->set_delay(std::chrono::milliseconds(10));
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
spdlog::details::log_msg msg{tp, source, "test_logger", spdlog::level::info, "message"}; spdlog::details::log_msg msg{tp, source, "test_logger", spdlog::log_level::info, "message"};
test_sink->log(msg); test_sink->log(msg);
} }
logger.log(tp, source, spdlog::level::info, "formatted message"); logger.log(tp, source, spdlog::log_level::info, "formatted message");
logger.log(tp, source, spdlog::level::info, "formatted message"); logger.log(tp, source, spdlog::log_level::info, "formatted message");
logger.log(tp, source, spdlog::level::info, "formatted message"); logger.log(tp, source, spdlog::log_level::info, "formatted message");
logger.log(tp, source, spdlog::level::info, "formatted message"); logger.log(tp, source, spdlog::log_level::info, "formatted message");
logger.log(source, spdlog::level::info, "formatted message"); // last line has different time_point logger.log(source, spdlog::log_level::info, "formatted message"); // last line has different time_point
// now the real test... that the times are the same. // now the real test... that the times are the same.
std::vector<std::string> lines = test_sink->lines(); std::vector<std::string> lines = test_sink->lines();