diff --git a/README.md b/README.md index 425773d5..a375e5a5 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ int main() spdlog::info("Positional args are {1} {0}..", "too", "supported"); spdlog::info("{:<30}", "left aligned"); - spdlog::set_level(spdlog::log_level::debug); // Set global log level to debug + spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug("This message should be displayed.."); // change log pattern @@ -220,14 +220,14 @@ void binary_example() void multi_sink_example() { auto console_sink = std::make_shared(); - console_sink->set_level(spdlog::log_level::warn); + console_sink->set_level(spdlog::level::warn); console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); auto file_sink = std::make_shared("logs/multisink.txt", true); - file_sink->set_level(spdlog::log_level::trace); + file_sink->set_level(spdlog::level::trace); spdlog::logger logger("multi_sink", {console_sink, file_sink}); - logger.set_level(spdlog::log_level::debug); + logger.set_level(spdlog::level::debug); logger.warn("this should appear in both console and 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([](const spdlog::details::log_msg &msg) { // for example you can be notified by sending an email to yourself }); - callback_sink->set_level(spdlog::log_level::err); + callback_sink->set_level(spdlog::level::err); auto console_sink = std::make_shared(); spdlog::logger logger("custom_callback_logger", {console_sink, callback_sink}); diff --git a/bench/bench.cpp b/bench/bench.cpp index 2896ae7b..924cbc9f 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -56,7 +56,7 @@ void bench_threaded_logging(size_t threads, int iters) spdlog::info(""); auto empty_logger = std::make_shared("level-off"); - empty_logger->set_level(spdlog::log_level::off); + empty_logger->set_level(spdlog::level::off); bench(iters, empty_logger); } @@ -79,7 +79,7 @@ void bench_single_threaded(int iters) spdlog::info(""); auto empty_logger = std::make_shared("level-off"); - empty_logger->set_level(spdlog::log_level::off); + empty_logger->set_level(spdlog::level::off); bench(iters, empty_logger); } @@ -208,7 +208,7 @@ void bench_c_string(int howmany, std::shared_ptr log) auto start = high_resolution_clock::now(); for (auto i = 0; i < howmany; ++i) { - spdlog::log(spdlog::log_level::info, msg); + spdlog::log(spdlog::level::info, msg); } auto delta = high_resolution_clock::now() - start; diff --git a/bench/formatter-bench.cpp b/bench/formatter-bench.cpp index 5d60dd18..a7b8bd10 100644 --- a/bench/formatter-bench.cpp +++ b/bench/formatter-bench.cpp @@ -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 "; spdlog::source_loc source_loc{"a/b/c/d/myfile.cpp", 123, "some_func()"}; - spdlog::details::log_msg msg(source_loc, logger_name, spdlog::log_level::info, text); + spdlog::details::log_msg msg(source_loc, logger_name, spdlog::level::info, text); for (auto _ : state) { diff --git a/bench/latency.cpp b/bench/latency.cpp index d9c97722..510d2e70 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) // disabled loggers auto disabled_logger = std::make_shared("bench", std::make_shared()); - disabled_logger->set_level(spdlog::log_level::off); + disabled_logger->set_level(spdlog::level::off); 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-runtime", bench_logger, disabled_logger); diff --git a/example/example.cpp b/example/example.cpp index 81df17ad..19fd0b10 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -47,16 +47,16 @@ int main(int, char *[]) spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left"); // Runtime log levels - spdlog::set_level(spdlog::log_level::info); // Set global log level to info + spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::log_level::trace); // Set specific logger's log level + spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::debug("This message should be displayed.."); // Customize msg format for all loggers spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"); spdlog::info("This an info message with custom format"); spdlog::set_pattern("%+"); // back to default format - spdlog::set_level(spdlog::log_level::info); + spdlog::set_level(spdlog::level::info); try { @@ -243,7 +243,7 @@ void udp_example() { spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091); auto my_logger = spdlog::udp_logger_mt("udplog", cfg); - my_logger->set_level(spdlog::log_level::debug); + my_logger->set_level(spdlog::level::debug); my_logger->info("hello world"); } @@ -251,14 +251,14 @@ void udp_example() void multi_sink_example() { auto console_sink = std::make_shared(); - console_sink->set_level(spdlog::log_level::warn); + console_sink->set_level(spdlog::level::warn); console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); auto file_sink = std::make_shared("logs/multisink.txt", true); - file_sink->set_level(spdlog::log_level::trace); + file_sink->set_level(spdlog::level::trace); spdlog::logger logger("multi_sink", {console_sink, file_sink}); - logger.set_level(spdlog::log_level::debug); + logger.set_level(spdlog::level::debug); logger.warn("this should appear in both console and 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); spdlog::set_default_logger(new_logger); - spdlog::set_level(spdlog::log_level::info); + spdlog::set_level(spdlog::level::info); spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::log_level::trace); + spdlog::set_level(spdlog::level::trace); spdlog::debug("This message should be displayed.."); spdlog::set_default_logger(old_logger); diff --git a/include/spdlog/async_logger-inl.h b/include/spdlog/async_logger-inl.h index 13da5940..8d980da2 100644 --- a/include/spdlog/async_logger-inl.h +++ b/include/spdlog/async_logger-inl.h @@ -64,7 +64,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg { for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) + if (sink->should_log(msg.log_level)) { SPDLOG_TRY { diff --git a/include/spdlog/cfg/helpers-inl.h b/include/spdlog/cfg/helpers-inl.h index f973fad7..5915436b 100644 --- a/include/spdlog/cfg/helpers-inl.h +++ b/include/spdlog/cfg/helpers-inl.h @@ -87,8 +87,8 @@ SPDLOG_INLINE void load_levels(const std::string &input) } auto key_vals = extract_key_vals_(input); - std::unordered_map levels; - log_level global_level = log_level::info; + std::unordered_map levels; + level global_level = level::info; bool global_level_found = false; for (auto &name_level : key_vals) @@ -97,7 +97,7 @@ SPDLOG_INLINE void load_levels(const std::string &input) auto level_name = to_lower_(name_level.second); auto level = level_from_str(level_name); // ignore unrecognized level names - if (level == log_level::off && level_name != "off") + if (level == level::off && level_name != "off") { continue; } diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index 413c8f1e..a8da7a91 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -12,22 +12,22 @@ namespace spdlog { -SPDLOG_INLINE spdlog::log_level level_from_str(const std::string &name) noexcept +SPDLOG_INLINE spdlog::level level_from_str(const std::string &name) noexcept { auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); if (it != std::end(level_string_views)) - return static_cast(std::distance(std::begin(level_string_views), it)); + return static_cast(std::distance(std::begin(level_string_views), it)); // check also for "warn" and "err" before giving up.. if (name == "warn") { - return spdlog::log_level::warn; + return spdlog::level::warn; } if (name == "err") { - return log_level::err; + return level::err; } - return log_level::off; + return level::off; } SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index bc433439..59d3084e 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -160,7 +160,7 @@ template using is_convertible_to_sv = std::enable_if_t>; // Log level enum -enum class log_level +enum class level { trace = SPDLOG_LEVEL_TRACE, debug = SPDLOG_LEVEL_DEBUG, @@ -173,9 +173,9 @@ enum class log_level }; #if defined(SPDLOG_NO_ATOMIC_LEVELS) - using atomic_level_t = details::null_atomic; + using atomic_level_t = details::null_atomic; #else - using atomic_level_t = std::atomic; + using atomic_level_t = std::atomic; #endif #if !defined(SPDLOG_LEVEL_NAMES) @@ -186,25 +186,25 @@ enum class log_level #define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"} #endif -constexpr size_t to_size_t(log_level level) noexcept +constexpr size_t to_size_t(level lvl) noexcept { - return static_cast(level); + return static_cast(lvl); } -constexpr auto levels_count = to_size_t(log_level::n_levels); +constexpr auto levels_count = to_size_t(level::n_levels); constexpr std::array level_string_views SPDLOG_LEVEL_NAMES; constexpr std::array short_level_names SPDLOG_SHORT_LEVEL_NAMES; -constexpr string_view_t to_string_view(spdlog::log_level lvl) noexcept +constexpr string_view_t to_string_view(spdlog::level lvl) noexcept { return level_string_views.at(to_size_t(lvl)); } -constexpr const char *to_short_c_str(spdlog::log_level lvl) noexcept +constexpr const char *to_short_c_str(spdlog::level lvl) noexcept { return short_level_names.at(to_size_t(lvl)); } -SPDLOG_API spdlog::log_level level_from_str(const std::string &name) noexcept; +SPDLOG_API spdlog::level level_from_str(const std::string &name) noexcept; diff --git a/include/spdlog/details/log_msg-inl.h b/include/spdlog/details/log_msg-inl.h index 5c81d8f3..728b9704 100644 --- a/include/spdlog/details/log_msg-inl.h +++ b/include/spdlog/details/log_msg-inl.h @@ -13,9 +13,9 @@ namespace spdlog { namespace details { SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name, - spdlog::log_level lvl, spdlog::string_view_t msg) + spdlog::level lvl, spdlog::string_view_t msg) : logger_name(a_logger_name) - , level(lvl) + , log_level(lvl) , time(log_time) #ifndef SPDLOG_NO_THREAD_ID , thread_id(os::thread_id()) @@ -25,11 +25,11 @@ SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::s {} SPDLOG_INLINE log_msg::log_msg( - spdlog::source_loc loc, string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg) + spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg) : log_msg(os::now(), loc, a_logger_name, lvl, msg) {} -SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::log_level lvl, spdlog::string_view_t msg) +SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg) : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) {} diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index 548810ea..d9ad57fd 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -11,14 +11,14 @@ namespace details { struct SPDLOG_API log_msg { log_msg() = default; - log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, log_level lvl, string_view_t msg); - log_msg(source_loc loc, string_view_t logger_name, log_level lvl, string_view_t msg); - log_msg(string_view_t logger_name, log_level lvl, string_view_t msg); + log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level lvl, string_view_t msg); + log_msg(source_loc loc, string_view_t logger_name, level lvl, string_view_t msg); + log_msg(string_view_t logger_name, level lvl, string_view_t msg); log_msg(const log_msg &other) = default; log_msg &operator=(const log_msg &other) = default; string_view_t logger_name; - log_level level{log_level::off}; + level log_level{level::off}; log_clock::time_point time; size_t thread_id{0}; diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index dc1afee0..d7ed8b9e 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -142,24 +142,24 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) } } -SPDLOG_INLINE void registry::set_level(log_level log_level) +SPDLOG_INLINE void registry::set_level(level level) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { - l.second->set_level(log_level); + l.second->set_level(level); } - global_log_level_ = log_level; + global_log_level_ = level; } -SPDLOG_INLINE void registry::flush_on(log_level log_level) +SPDLOG_INLINE void registry::flush_on(level level) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { - l.second->flush_on(log_level); + l.second->flush_on(level); } - flush_level_ = log_level; + flush_level_ = level; } SPDLOG_INLINE void registry::set_error_handler(err_handler handler) @@ -235,7 +235,7 @@ SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registrat automatic_registration_ = automatic_registration; } -SPDLOG_INLINE void registry::set_levels(log_levels levels, log_level *global_level) +SPDLOG_INLINE void registry::set_levels(log_levels levels, level *global_level) { std::lock_guard lock(logger_map_mutex_); log_levels_ = std::move(levels); diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 0c3c47b5..8e65f166 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -27,7 +27,7 @@ class thread_pool; class SPDLOG_API registry { public: - using log_levels = std::unordered_map; + using log_levels = std::unordered_map; registry(const registry &) = delete; registry &operator=(const registry &) = delete; @@ -53,9 +53,9 @@ public: // Set global formatter. Each sink in each logger will get a clone of this object void set_formatter(std::unique_ptr formatter); - void set_level(log_level log_level); + void set_level(level level); - void flush_on(log_level log_level); + void flush_on(level level); template void flush_every(std::chrono::duration interval) @@ -83,7 +83,7 @@ public: void set_automatic_registration(bool automatic_registration); // set levels for all existing/future loggers. global_level can be null if should not set. - void set_levels(log_levels levels, log_level *global_level); + void set_levels(log_levels levels, level *global_level); static registry &instance(); @@ -101,8 +101,8 @@ private: std::unordered_map> loggers_; log_levels log_levels_; std::unique_ptr formatter_; - spdlog::log_level global_log_level_ = log_level::info; - log_level flush_level_ = log_level::off; + spdlog::level global_log_level_ = level::info; + level flush_level_ = level::off; err_handler err_handler_; std::shared_ptr tp_; std::unique_ptr periodic_flusher_; diff --git a/include/spdlog/logger-inl.h b/include/spdlog/logger-inl.h index c137b8cc..33c4d8f8 100644 --- a/include/spdlog/logger-inl.h +++ b/include/spdlog/logger-inl.h @@ -31,14 +31,14 @@ SPDLOG_INLINE logger::logger(logger &&other) noexcept , custom_err_handler_(std::move(other.custom_err_handler_)) {} -SPDLOG_INLINE void logger::set_level(log_level log_level) +SPDLOG_INLINE void logger::set_level(level level) { - level_.store(log_level); + level_.store(level); } -SPDLOG_INLINE log_level logger::level() const +SPDLOG_INLINE level logger::log_level() const { - return static_cast(level_.load(std::memory_order_relaxed)); + return static_cast(level_.load(std::memory_order_relaxed)); } SPDLOG_INLINE const std::string &logger::name() const @@ -77,14 +77,14 @@ SPDLOG_INLINE void logger::flush() flush_(); } -SPDLOG_INLINE void logger::flush_on(log_level log_level) +SPDLOG_INLINE void logger::flush_on(level level) { - flush_level_.store(log_level); + flush_level_.store(level); } -SPDLOG_INLINE log_level logger::flush_level() const +SPDLOG_INLINE level logger::flush_level() const { - return static_cast(flush_level_.load(std::memory_order_relaxed)); + return static_cast(flush_level_.load(std::memory_order_relaxed)); } // sinks @@ -127,7 +127,7 @@ SPDLOG_INLINE void logger::flush_() SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) { auto flush_level = flush_level_.load(std::memory_order_relaxed); - return (msg.level >= flush_level) && (msg.level != log_level::off); + return (msg.log_level >= flush_level) && (msg.log_level != level::off); } SPDLOG_INLINE void logger::err_handler_(const std::string &msg) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 88d46c3f..fb08113a 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -77,7 +77,7 @@ public: // log functions template - void log(source_loc loc, log_level lvl, format_string_t fmt, Args &&...args) + void log(source_loc loc, level lvl, format_string_t fmt, Args &&...args) { if (should_log(lvl)) { @@ -86,7 +86,7 @@ public: } template - void log(log_level lvl, format_string_t fmt, Args &&...args) + void log(level lvl, format_string_t fmt, Args &&...args) { if (should_log(lvl)) { @@ -95,7 +95,7 @@ public: } template, typename... Args> - void log(source_loc loc, log_level lvl, S fmt, Args &&...args) + void log(source_loc loc, level lvl, S fmt, Args &&...args) { if (should_log(lvl)) { @@ -104,7 +104,7 @@ public: } // log with no format string, just string message - void log(source_loc loc, log_level lvl, string_view_t msg) + void log(source_loc loc, level lvl, string_view_t msg) { if (should_log(lvl)) { @@ -112,7 +112,7 @@ public: } } - void log(log_level lvl, string_view_t msg) + void log(level lvl, string_view_t msg) { if (should_log(lvl)) { @@ -121,7 +121,7 @@ public: } // support for custom time - void log(log_clock::time_point log_time, source_loc loc, log_level lvl, string_view_t msg) + void log(log_clock::time_point log_time, source_loc loc, level lvl, string_view_t msg) { if (should_log(lvl)) { @@ -133,150 +133,150 @@ public: template void trace(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::trace, fmt.fmt_string, std::forward(args)...); } template void debug(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::debug, fmt.fmt_string, std::forward(args)...); } template void info(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::info, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::info, fmt.fmt_string, std::forward(args)...); } template void warn(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::warn, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::warn, fmt.fmt_string, std::forward(args)...); } template void error(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::err, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::err, fmt.fmt_string, std::forward(args)...); } template void critical(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::critical, fmt.fmt_string, std::forward(args)...); } // log functions with no format string, just string void trace(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::trace, msg); + log(loc, level::trace, msg); } void debug(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::debug, msg); + log(loc, level::debug, msg); } void info(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::info, msg); + log(loc, level::info, msg); } void warn(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::warn, msg); + log(loc, level::warn, msg); } void error(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::err, msg); + log(loc, level::err, msg); } void critical(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::critical, msg); + log(loc, level::critical, msg); } #else template void trace(format_string_t fmt, Args &&...args) { - log(log_level::trace, fmt, std::forward(args)...); + log(level::trace, fmt, std::forward(args)...); } template void debug(format_string_t fmt, Args &&...args) { - log(log_level::debug, fmt, std::forward(args)...); + log(level::debug, fmt, std::forward(args)...); } template void info(format_string_t fmt, Args &&...args) { - log(log_level::info, fmt, std::forward(args)...); + log(level::info, fmt, std::forward(args)...); } template void warn(format_string_t fmt, Args &&...args) { - log(log_level::warn, fmt, std::forward(args)...); + log(level::warn, fmt, std::forward(args)...); } template void error(format_string_t fmt, Args &&...args) { - log(log_level::err, fmt, std::forward(args)...); + log(level::err, fmt, std::forward(args)...); } template void critical(format_string_t fmt, Args &&...args) { - log(log_level::critical, fmt, std::forward(args)...); + log(level::critical, fmt, std::forward(args)...); } // log functions with no format string, just string void trace(string_view_t msg) { - log(log_level::trace, msg); + log(level::trace, msg); } void debug(string_view_t msg) { - log(log_level::debug, msg); + log(level::debug, msg); } void info(string_view_t msg) { - log(log_level::info, msg); + log(level::info, msg); } inline void warn(string_view_t msg) { - log(log_level::warn, msg); + log(level::warn, msg); } void error(string_view_t msg) { - log(log_level::err, msg); + log(level::err, msg); } void critical(string_view_t msg) { - log(log_level::critical, msg); + log(level::critical, msg); } #endif // return true if logging is enabled for the given level. - [[nodiscard]] bool should_log(log_level msg_level) const + [[nodiscard]] bool should_log(level msg_level) const { return msg_level >= level_.load(std::memory_order_relaxed); } // set the level of logging - void set_level(log_level log_level); + void set_level(level level); // return the active log level - [[nodiscard]] log_level level() const; + [[nodiscard]] level log_level() const; // return the name of the logger [[nodiscard]] const std::string &name() const; @@ -293,8 +293,8 @@ public: // flush functions void flush(); - void flush_on(log_level log_level); - [[nodiscard]] log_level flush_level() const; + void flush_on(level level); + [[nodiscard]] level flush_level() const; // sinks [[nodiscard]] const std::vector &sinks() const; @@ -310,13 +310,13 @@ public: protected: std::string name_; std::vector sinks_; - spdlog::atomic_level_t level_{log_level::info}; - spdlog::atomic_level_t flush_level_{log_level::off}; + spdlog::atomic_level_t level_{level::info}; + spdlog::atomic_level_t flush_level_{level::off}; err_handler custom_err_handler_{nullptr}; // common implementation for after templated public api has been resolved to format string and args template - void log_with_format_(source_loc loc, log_level lvl, string_view_t fmt, Args &&...args) + void log_with_format_(source_loc loc, level lvl, string_view_t fmt, Args &&...args) { assert(should_log(lvl)); SPDLOG_TRY @@ -336,10 +336,10 @@ protected: // log the given message (if the given log level is high enough) virtual void sink_it_(const details::log_msg &msg) { - assert(should_log(msg.level)); + assert(should_log(msg.log_level)); for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) + if (sink->should_log(msg.log_level)) { SPDLOG_TRY { diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index a27895a3..feb2138c 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -129,7 +129,7 @@ public: void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const string_view_t &level_name = to_string_view(msg.level); + const string_view_t &level_name = to_string_view(msg.log_level); ScopedPadder p(level_name.size(), padinfo_, dest); fmt_helper::append_string_view(level_name, dest); } @@ -146,7 +146,7 @@ public: void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - string_view_t level_name{to_short_c_str(msg.level)}; + string_view_t level_name{to_short_c_str(msg.log_level)}; ScopedPadder p(level_name.size(), padinfo_, dest); fmt_helper::append_string_view(level_name, dest); } @@ -991,8 +991,8 @@ public: dest.push_back('['); // wrap the level name with color msg.color_range_start = dest.size(); - // fmt_helper::append_string_view(log_level::to_c_str(msg.level), dest); - fmt_helper::append_string_view(to_string_view(msg.level), dest); + // fmt_helper::append_string_view(level::to_c_str(msg.log_level), dest); + fmt_helper::append_string_view(to_string_view(msg.log_level), dest); msg.color_range_end = dest.size(); dest.push_back(']'); dest.push_back(' '); diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index 793b778b..34480ba0 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -41,7 +41,7 @@ public: protected: void sink_it_(const details::log_msg &msg) override { - const android_LogPriority priority = convert_to_android_(msg.level); + const android_LogPriority priority = convert_to_android_(msg.log_level); memory_buf_t formatted; if (use_raw_msg_) { @@ -92,21 +92,21 @@ private: return __android_log_buf_write(ID, prio, tag, text); } - static android_LogPriority convert_to_android_(spdlog::log_level level) + static android_LogPriority convert_to_android_(spdlog::level level) { switch (level) { - case spdlog::log_level::trace: + case spdlog::level::trace: return ANDROID_LOG_VERBOSE; - case spdlog::log_level::debug: + case spdlog::level::debug: return ANDROID_LOG_DEBUG; - case spdlog::log_level::info: + case spdlog::level::info: return ANDROID_LOG_INFO; - case spdlog::log_level::warn: + case spdlog::level::warn: return ANDROID_LOG_WARN; - case spdlog::log_level::err: + case spdlog::level::err: return ANDROID_LOG_ERROR; - case spdlog::log_level::critical: + case spdlog::level::critical: return ANDROID_LOG_FATAL; default: return ANDROID_LOG_DEFAULT; diff --git a/include/spdlog/sinks/ansicolor_sink-inl.h b/include/spdlog/sinks/ansicolor_sink-inl.h index 34bee0b0..9289b49a 100644 --- a/include/spdlog/sinks/ansicolor_sink-inl.h +++ b/include/spdlog/sinks/ansicolor_sink-inl.h @@ -21,17 +21,17 @@ SPDLOG_INLINE ansicolor_sink::ansicolor_sink(FILE *target_file, co { set_color_mode(mode); - colors_.at(to_size_t(log_level::trace)) = to_string_(white); - colors_.at(to_size_t(log_level::debug)) = to_string_(cyan); - colors_.at(to_size_t(log_level::info)) = to_string_(green); - colors_.at(to_size_t(log_level::warn)) = to_string_(yellow_bold); - colors_.at(to_size_t(log_level::err)) = to_string_(red_bold); - colors_.at(to_size_t(log_level::critical)) = to_string_(bold_on_red); - colors_.at(to_size_t(log_level::off)) = to_string_(reset); + colors_.at(to_size_t(level::trace)) = to_string_(white); + colors_.at(to_size_t(level::debug)) = to_string_(cyan); + colors_.at(to_size_t(level::info)) = to_string_(green); + colors_.at(to_size_t(level::warn)) = to_string_(yellow_bold); + colors_.at(to_size_t(level::err)) = to_string_(red_bold); + colors_.at(to_size_t(level::critical)) = to_string_(bold_on_red); + colors_.at(to_size_t(level::off)) = to_string_(reset); } template -SPDLOG_INLINE void ansicolor_sink::set_color(log_level color_level, string_view_t color) +SPDLOG_INLINE void ansicolor_sink::set_color(level color_level, string_view_t color) { std::lock_guard lock(mutex_); colors_.at(to_size_t(color_level)) = to_string_(color); @@ -52,7 +52,7 @@ SPDLOG_INLINE void ansicolor_sink::log(const details::log_msg &msg // before color range print_range_(formatted, 0, msg.color_range_start); // in color range - print_ccode_(colors_.at(static_cast(msg.level))); + print_ccode_(colors_.at(static_cast(msg.log_level))); print_range_(formatted, msg.color_range_start, msg.color_range_end); print_ccode_(reset); // after color range diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index d05f12ee..0a5fc39f 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -35,7 +35,7 @@ public: ansicolor_sink &operator=(const ansicolor_sink &other) = delete; ansicolor_sink &operator=(ansicolor_sink &&other) = delete; - void set_color(log_level color_level, string_view_t color); + void set_color(level color_level, string_view_t color); void set_color_mode(color_mode mode); bool should_color(); diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index 8eb1aa95..394ae9c3 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -59,7 +59,7 @@ protected: { for (auto &sub_sink : sinks_) { - if (sub_sink->should_log(msg.level)) + if (sub_sink->should_log(msg.log_level)) { sub_sink->log(msg); } diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index 448c25ac..c70b00c6 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -20,7 +20,7 @@ // #include // // int main() { -// auto dup_filter = std::make_shared(std::chrono::seconds(5), log_level::info); +// auto dup_filter = std::make_shared(std::chrono::seconds(5), level::info); // dup_filter->add_sink(std::make_shared()); // spdlog::logger l("logger", dup_filter); // l.info("Hello"); @@ -41,7 +41,7 @@ class dup_filter_sink : public dist_sink { public: template - explicit dup_filter_sink(std::chrono::duration max_skip_duration, log_level notification_level = log_level::info) + explicit dup_filter_sink(std::chrono::duration max_skip_duration, level notification_level = level::info) : max_skip_duration_{max_skip_duration} , log_level_{notification_level} {} @@ -51,7 +51,7 @@ protected: log_clock::time_point last_msg_time_; std::string last_msg_payload_; size_t skip_counter_ = 0; - log_level log_level_; + level log_level_; void sink_it_(const details::log_msg &msg) override { diff --git a/include/spdlog/sinks/mongo_sink.h b/include/spdlog/sinks/mongo_sink.h index f491b50e..5b52ef09 100644 --- a/include/spdlog/sinks/mongo_sink.h +++ b/include/spdlog/sinks/mongo_sink.h @@ -66,8 +66,8 @@ protected: if (client_ != nullptr) { - auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << log_level::to_string_view(msg.level).data() - << "level_num" << msg.level << "message" << std::string(msg.payload.begin(), msg.payload.end()) + auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.log_level).data() + << "level_num" << msg.log_level << "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id" << static_cast(msg.thread_id) << finalize; client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index e63098f8..eb832801 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -29,7 +29,7 @@ template inline std::shared_ptr null_logger_mt(const std::string &logger_name) { auto null_logger = Factory::template create(logger_name); - null_logger->set_level(log_level::off); + null_logger->set_level(level::off); return null_logger; } @@ -37,7 +37,7 @@ template inline std::shared_ptr null_logger_st(const std::string &logger_name) { auto null_logger = Factory::template create(logger_name); - null_logger->set_level(log_level::off); + null_logger->set_level(level::off); return null_logger; } diff --git a/include/spdlog/sinks/qt_sinks.h b/include/spdlog/sinks/qt_sinks.h index 9cf93b1e..48e50d8a 100644 --- a/include/spdlog/sinks/qt_sinks.h +++ b/include/spdlog/sinks/qt_sinks.h @@ -86,23 +86,23 @@ public: QTextCharFormat format; // trace format.setForeground(dark_colors ? Qt::darkGray : Qt::gray); - colors_.at(log_level::trace) = format; + colors_.at(level::trace) = format; // debug format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan); - colors_.at(log_level::debug) = format; + colors_.at(level::debug) = format; // info format.setForeground(dark_colors ? Qt::darkGreen : Qt::green); - colors_.at(log_level::info) = format; + colors_.at(level::info) = format; // warn format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow); - colors_.at(spdlog::log_level::warn) = format; + colors_.at(spdlog::level::warn) = format; // err format.setForeground(Qt::red); - colors_.at(log_level::err) = format; + colors_.at(level::err) = format; // critical format.setForeground(Qt::white); format.setBackground(Qt::red); - colors_.at(log_level::critical) = format; + colors_.at(level::critical) = format; } ~qt_color_sink() @@ -116,13 +116,13 @@ public: default_color_ = format; } - void set_level_color(log_level color_level, QTextCharFormat format) + void set_level_color(level color_level, QTextCharFormat format) { // std::lock_guard lock(base_sink::mutex_); colors_.at(static_cast(color_level)) = format; } - QTextCharFormat &get_level_color(log_level color_level) + QTextCharFormat &get_level_color(level color_level) { std::lock_guard lock(base_sink::mutex_); return colors_.at(static_cast(color_level)); @@ -185,7 +185,7 @@ protected: qt_text_edit_, // text edit to append to std::move(payload), // text to append default_color_, // default color - colors_.at(msg.level), // color to apply + colors_.at(msg.log_level), // color to apply color_range_start, // color range start color_range_end}; // color range end @@ -238,7 +238,7 @@ protected: int max_lines_; bool is_utf8_; QTextCharFormat default_color_; - std::array colors_; + std::array colors_; }; #include "spdlog/details/null_mutex.h" diff --git a/include/spdlog/sinks/sink-inl.h b/include/spdlog/sinks/sink-inl.h index 16664c58..f33ada40 100644 --- a/include/spdlog/sinks/sink-inl.h +++ b/include/spdlog/sinks/sink-inl.h @@ -9,17 +9,16 @@ #include -SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::log_level msg_level) const +SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level msg_level) const { return msg_level >= level_.load(std::memory_order_relaxed); } -SPDLOG_INLINE void spdlog::sinks::sink::set_level(log_level log_level) +SPDLOG_INLINE void spdlog::sinks::sink::set_level(level level) { - level_.store(log_level, std::memory_order_relaxed); + level_.store(level, std::memory_order_relaxed); } -SPDLOG_INLINE spdlog::log_level spdlog::sinks::sink::level() const -{ - return static_cast(level_.load(std::memory_order_relaxed)); +SPDLOG_INLINE spdlog::level spdlog::sinks::sink::log_level() const { + return static_cast(level_.load(std::memory_order_relaxed)); } diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index c8d3005c..d63b7a01 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -18,13 +18,13 @@ public: virtual void set_pattern(const std::string &pattern) = 0; virtual void set_formatter(std::unique_ptr sink_formatter) = 0; - void set_level(log_level log_level); - log_level level() const; - bool should_log(log_level msg_level) const; + void set_level(level level); + level log_level() const; + bool should_log(level msg_level) const; protected: // sink log level - default is all - atomic_level_t level_{log_level::trace}; + atomic_level_t level_{level::trace}; }; } // namespace sinks diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index 3bf04d76..66b294cb 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -23,13 +23,13 @@ class syslog_sink : public base_sink public: syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) : enable_formatting_{enable_formatting} - , syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG, - /* spdlog::log_level::debug */ LOG_DEBUG, - /* spdlog::log_level::info */ LOG_INFO, - /* spdlog::log_level::warn */ LOG_WARNING, - /* spdlog::log_level::err */ LOG_ERR, - /* spdlog::log_level::critical */ LOG_CRIT, - /* spdlog::log_level::off */ LOG_INFO}} + , syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, + /* spdlog::level::debug */ LOG_DEBUG, + /* spdlog::level::info */ LOG_INFO, + /* spdlog::level::warn */ LOG_WARNING, + /* spdlog::level::err */ LOG_ERR, + /* spdlog::level::critical */ LOG_CRIT, + /* spdlog::level::off */ LOG_INFO}} , ident_{std::move(ident)} { // set ident to be program name if empty @@ -84,7 +84,7 @@ private: // int syslog_prio_from_level(const details::log_msg &msg) const { - return syslog_levels_.at(static_cast(msg.level)); + return syslog_levels_.at(static_cast(msg.log_level)); } }; diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index 1b5cc5a9..ed44c991 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -27,13 +27,13 @@ public: systemd_sink(std::string ident = "", bool enable_formatting = false) : ident_{std::move(ident)} , enable_formatting_{enable_formatting} - , syslog_levels_{{/* spdlog::log_level::trace */ LOG_DEBUG, - /* spdlog::log_level::debug */ LOG_DEBUG, - /* spdlog::log_level::info */ LOG_INFO, - /* spdlog::log_level::warn */ LOG_WARNING, - /* spdlog::log_level::err */ LOG_ERR, - /* spdlog::log_level::critical */ LOG_CRIT, - /* spdlog::log_level::off */ LOG_INFO}} + , syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, + /* spdlog::level::debug */ LOG_DEBUG, + /* spdlog::level::info */ LOG_INFO, + /* spdlog::level::warn */ LOG_WARNING, + /* spdlog::level::err */ LOG_ERR, + /* spdlog::level::critical */ LOG_CRIT, + /* spdlog::level::off */ LOG_INFO}} {} ~systemd_sink() override {} @@ -75,7 +75,7 @@ protected: if (msg.source.empty()) { // Note: function call inside '()' to avoid macro expansion - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), "PRIORITY=%d", syslog_level(msg.level), + err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), "PRIORITY=%d", syslog_level(msg.log_level), #ifndef SPDLOG_NO_THREAD_ID "TID=%zu", details::os::thread_id(), #endif @@ -83,7 +83,7 @@ protected: } else { - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), "PRIORITY=%d", syslog_level(msg.level), + err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), "PRIORITY=%d", syslog_level(msg.log_level), #ifndef SPDLOG_NO_THREAD_ID "TID=%zu", details::os::thread_id(), #endif @@ -97,7 +97,7 @@ protected: } } - int syslog_level(log_level l) + int syslog_level(level l) { return syslog_levels_.at(static_cast(l)); } diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index f3d16263..11ecec51 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -172,21 +172,21 @@ struct eventlog { static WORD get_event_type(details::log_msg const &msg) { - switch (msg.level) + switch (msg.log_level) { - case log_level::trace: - case log_level::debug: + case level::trace: + case level::debug: return EVENTLOG_SUCCESS; - case log_level::info: + case level::info: return EVENTLOG_INFORMATION_TYPE; - case spdlog::log_level::warn: + case spdlog::level::warn: return EVENTLOG_WARNING_TYPE; - case log_level::err: - case log_level::critical: - case log_level::off: + case level::err: + case level::critical: + case level::off: return EVENTLOG_ERROR_TYPE; default: @@ -196,7 +196,7 @@ struct eventlog static WORD get_event_category(details::log_msg const &msg) { - return (WORD)msg.level; + return (WORD)msg.log_level; } }; diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 6f26c3d8..acffe2b6 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -24,14 +24,14 @@ SPDLOG_INLINE wincolor_sink::wincolor_sink(void *out_handle, color set_color_mode_impl(mode); // set level colors - colors_.at(to_size_t(log_level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white - colors_.at(to_size_t(log_level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan - colors_.at(to_size_t(log_level::info)) = FOREGROUND_GREEN; // green - colors_.at(to_size_t(spdlog::log_level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow - colors_.at(to_size_t(log_level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red - colors_.at(to_size_t(log_level::critical)) = + colors_.at(to_size_t(level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white + colors_.at(to_size_t(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan + colors_.at(to_size_t(level::info)) = FOREGROUND_GREEN; // green + colors_.at(to_size_t(spdlog::level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow + colors_.at(to_size_t(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red + colors_.at(to_size_t(level::critical)) = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // intense white on red background - colors_.at(to_size_t(log_level::off)) = 0; + colors_.at(to_size_t(level::off)) = 0; } template @@ -42,7 +42,7 @@ SPDLOG_INLINE wincolor_sink::~wincolor_sink() // change the color for the given level template -void SPDLOG_INLINE wincolor_sink::set_color(log_level level, std::uint16_t color) +void SPDLOG_INLINE wincolor_sink::set_color(level level, std::uint16_t color) { std::lock_guard lock(mutex_); colors_[static_cast(level)] = color; @@ -66,7 +66,7 @@ void SPDLOG_INLINE wincolor_sink::log(const details::log_msg &msg) // before color range print_range_(formatted, 0, msg.color_range_start); // in color range - auto orig_attribs = static_cast(set_foreground_color_(colors_[static_cast(msg.level)])); + auto orig_attribs = static_cast(set_foreground_color_(colors_[static_cast(msg.log_level)])); print_range_(formatted, msg.color_range_start, msg.color_range_end); // reset to orig colors ::SetConsoleTextAttribute(static_cast(out_handle_), orig_attribs); diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 78a9d373..92d95cb3 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -31,7 +31,7 @@ public: wincolor_sink &operator=(const wincolor_sink &other) = delete; // change the color for the given level - void set_color(log_level level, std::uint16_t color); + void set_color(level level, std::uint16_t color); void log(const details::log_msg &msg) final override; void flush() final override; void set_pattern(const std::string &pattern) override final; diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index c2e4530d..9d476bd8 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -32,24 +32,24 @@ SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) set_formatter(std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); } -SPDLOG_INLINE log_level get_level() +SPDLOG_INLINE level get_level() { - return default_logger_raw()->level(); + return default_logger_raw()->log_level(); } -SPDLOG_INLINE bool should_log(log_level log_level) +SPDLOG_INLINE bool should_log(level level) { - return default_logger_raw()->should_log(log_level); + return default_logger_raw()->should_log(level); } -SPDLOG_INLINE void set_level(log_level log_level) +SPDLOG_INLINE void set_level(level level) { - details::registry::instance().set_level(log_level); + details::registry::instance().set_level(level); } -SPDLOG_INLINE void flush_on(log_level log_level) +SPDLOG_INLINE void flush_on(level level) { - details::registry::instance().flush_on(log_level); + details::registry::instance().flush_on(level); } SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 0211301a..d7d8b0cf 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -59,16 +59,16 @@ SPDLOG_API void set_formatter(std::unique_ptr formatter); SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); // Get global logging level -SPDLOG_API log_level get_level(); +SPDLOG_API level get_level(); // Set global logging level -SPDLOG_API void set_level(log_level log_level); +SPDLOG_API void set_level(level level); // Determine whether the default logger should log messages with a certain level -SPDLOG_API bool should_log(log_level lvl); +SPDLOG_API bool should_log(level lvl); // Set global flush level -SPDLOG_API void flush_on(log_level log_level); +SPDLOG_API void flush_on(level level); // Start/Restart a periodic flusher thread // Warning: Use only if all your loggers are thread safe! @@ -132,25 +132,25 @@ SPDLOG_API void set_default_logger(std::shared_ptr default_logge SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); template -inline void log(source_loc source, log_level lvl, format_string_t fmt, Args &&...args) +inline void log(source_loc source, level lvl, format_string_t fmt, Args &&...args) { default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); } template -inline void log(log_level lvl, format_string_t fmt, Args &&...args) +inline void log(level lvl, format_string_t fmt, Args &&...args) { default_logger_raw()->log(lvl, fmt, std::forward(args)...); } template, typename... Args> -inline void log(source_loc loc, log_level lvl, S fmt, Args &&...args) +inline void log(source_loc loc, level lvl, S fmt, Args &&...args) { default_logger_raw()->log(loc, lvl, fmt, std::forward(args)...); } template, typename... Args> -inline void log(log_level lvl, S fmt, Args &&...args) +inline void log(level lvl, S fmt, Args &&...args) { default_logger_raw()->log(lvl, fmt, std::forward(args)...); } @@ -159,135 +159,135 @@ inline void log(log_level lvl, S fmt, Args &&...args) template inline void trace(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::trace, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::trace, fmt.fmt_string, std::forward(args)...); } template inline void debug(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::debug, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::debug, fmt.fmt_string, std::forward(args)...); } template inline void info(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::info, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::info, fmt.fmt_string, std::forward(args)...); } template inline void warn(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, spdlog::log_level::warn, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, spdlog::level::warn, fmt.fmt_string, std::forward(args)...); } template inline void error(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::err, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::err, fmt.fmt_string, std::forward(args)...); } template inline void critical(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, log_level::critical, fmt.fmt_string, std::forward(args)...); + log(fmt.loc, level::critical, fmt.fmt_string, std::forward(args)...); } // log functions with no format string, just string inline void trace(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::trace, msg); + log(loc, level::trace, msg); } inline void debug(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::debug, msg); + log(loc, level::debug, msg); } inline void info(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::info, msg); + log(loc, level::info, msg); } inline void warn(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, spdlog::log_level::warn, msg); + log(loc, spdlog::level::warn, msg); } inline void error(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::err, msg); + log(loc, level::err, msg); } inline void critical(string_view_t msg, source_loc loc = source_loc::current()) { - log(loc, log_level::critical, msg); + log(loc, level::critical, msg); } #else template inline void trace(format_string_t fmt, Args &&...args) { - log(log_level::trace, fmt, std::forward(args)...); + log(level::trace, fmt, std::forward(args)...); } template inline void debug(format_string_t fmt, Args &&...args) { - log(log_level::debug, fmt, std::forward(args)...); + log(level::debug, fmt, std::forward(args)...); } template inline void info(format_string_t fmt, Args &&...args) { - log(log_level::info, fmt, std::forward(args)...); + log(level::info, fmt, std::forward(args)...); } template inline void warn(format_string_t fmt, Args &&...args) { - log(log_level::warn, fmt, std::forward(args)...); + log(level::warn, fmt, std::forward(args)...); } template inline void error(format_string_t fmt, Args &&...args) { - log(log_level::err, fmt, std::forward(args)...); + log(level::err, fmt, std::forward(args)...); } template inline void critical(format_string_t fmt, Args &&...args) { - log(log_level::critical, fmt, std::forward(args)...); + log(level::critical, fmt, std::forward(args)...); } // log functions with no format string, just string inline void trace(string_view_t msg) { - log(log_level::trace, msg); + log(level::trace, msg); } inline void debug(string_view_t msg) { - log(log_level::debug, msg); + log(level::debug, msg); } inline void info(string_view_t msg) { - log(log_level::info, msg); + log(level::info, msg); } inline void warn(string_view_t msg) { - log(log_level::warn, msg); + log(level::warn, msg); } inline void error(string_view_t msg) { - log(log_level::err, msg); + log(level::err, msg); } inline void critical(string_view_t msg) { - log(log_level::critical, msg); + log(level::critical, msg); } #endif @@ -314,7 +314,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE -# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::trace, __VA_ARGS__) +# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) # define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 @@ -322,7 +322,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG -# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::debug, __VA_ARGS__) +# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) # define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 @@ -330,7 +330,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO -# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::info, __VA_ARGS__) +# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) # define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_INFO(logger, ...) (void)0 @@ -338,7 +338,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN -# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::warn, __VA_ARGS__) +# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) # define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_WARN(logger, ...) (void)0 @@ -346,7 +346,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR -# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::err, __VA_ARGS__) +# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) # define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 @@ -354,7 +354,7 @@ inline void critical(string_view_t msg) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL -# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::log_level::critical, __VA_ARGS__) +# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) # define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) #else # define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d53eb9c8..af4fe57a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,7 +46,9 @@ set(SPDLOG_UTESTS_SOURCES test_stopwatch.cpp test_circular_q.cpp test_ringbuffer_sink.cpp - test_source_location.cpp) + test_source_location.cpp + test_log_level.cpp +) if(NOT SPDLOG_NO_EXCEPTIONS) list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp) diff --git a/tests/test_cfg.cpp b/tests/test_cfg.cpp index f58d500c..2915c500 100644 --- a/tests/test_cfg.cpp +++ b/tests/test_cfg.cpp @@ -19,9 +19,9 @@ TEST_CASE("env", "[cfg]") setenv("SPDLOG_LEVEL", "l1=warn", 1); #endif load_env_levels(); - REQUIRE(l1->level() == spdlog::log_level::warn); + REQUIRE(l1->log_level() == spdlog::level::warn); spdlog::set_default_logger(spdlog::create("cfg-default")); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } TEST_CASE("argv1", "[cfg]") @@ -30,8 +30,8 @@ TEST_CASE("argv1", "[cfg]") const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"}; load_argv_levels(2, argv); auto l1 = spdlog::create("l1"); - REQUIRE(l1->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + REQUIRE(l1->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } TEST_CASE("argv2", "[cfg]") @@ -40,60 +40,60 @@ TEST_CASE("argv2", "[cfg]") const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"}; load_argv_levels(2, argv); auto l1 = spdlog::create("l1"); - REQUIRE(l1->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace); + REQUIRE(l1->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::trace); } TEST_CASE("argv3", "[cfg]") { - spdlog::set_level(spdlog::log_level::trace); + spdlog::set_level(spdlog::level::trace); spdlog::drop("l1"); const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk_name=warn"}; load_argv_levels(2, argv); auto l1 = spdlog::create("l1"); - REQUIRE(l1->level() == spdlog::log_level::trace); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace); + REQUIRE(l1->log_level() == spdlog::level::trace); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::trace); } TEST_CASE("argv4", "[cfg]") { - spdlog::set_level(spdlog::log_level::info); + spdlog::set_level(spdlog::level::info); spdlog::drop("l1"); const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"}; load_argv_levels(2, argv); auto l1 = spdlog::create("l1"); - REQUIRE(l1->level() == spdlog::log_level::info); + REQUIRE(l1->log_level() == spdlog::level::info); } TEST_CASE("argv5", "[cfg]") { - spdlog::set_level(spdlog::log_level::info); + spdlog::set_level(spdlog::level::info); spdlog::drop("l1"); const char *argv[] = {"ignore", "ignore", "SPDLOG_LEVEL=l1=warn,trace"}; load_argv_levels(3, argv); auto l1 = spdlog::create("l1"); - REQUIRE(l1->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::trace); - spdlog::set_level(spdlog::log_level::info); + REQUIRE(l1->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::trace); + spdlog::set_level(spdlog::level::info); } TEST_CASE("argv6", "[cfg]") { - spdlog::set_level(spdlog::log_level::err); + spdlog::set_level(spdlog::level::err); const char *argv[] = {""}; load_argv_levels(1, argv); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::err); - spdlog::set_level(spdlog::log_level::info); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::err); + spdlog::set_level(spdlog::level::info); } TEST_CASE("argv7", "[cfg]") { - spdlog::set_level(spdlog::log_level::err); + spdlog::set_level(spdlog::level::err); const char *argv[] = {""}; load_argv_levels(0, argv); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::err); - spdlog::set_level(spdlog::log_level::info); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::err); + spdlog::set_level(spdlog::level::info); } TEST_CASE("level-not-set-test1", "[cfg]") @@ -102,9 +102,9 @@ TEST_CASE("level-not-set-test1", "[cfg]") const char *argv[] = {"ignore", ""}; load_argv_levels(2, argv); auto l1 = spdlog::create("l1"); - l1->set_level(spdlog::log_level::trace); - REQUIRE(l1->level() == spdlog::log_level::trace); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + l1->set_level(spdlog::level::trace); + REQUIRE(l1->log_level() == spdlog::level::trace); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } 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"}; auto l1 = spdlog::create("l1"); - l1->set_level(spdlog::log_level::warn); + l1->set_level(spdlog::level::warn); auto l2 = spdlog::create("l2"); - l2->set_level(spdlog::log_level::warn); + l2->set_level(spdlog::level::warn); load_argv_levels(2, argv); - REQUIRE(l1->level() == spdlog::log_level::trace); - REQUIRE(l2->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + REQUIRE(l1->log_level() == spdlog::level::trace); + REQUIRE(l2->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } TEST_CASE("level-not-set-test3", "[cfg]") @@ -136,9 +136,9 @@ TEST_CASE("level-not-set-test3", "[cfg]") auto l1 = spdlog::create("l1"); auto l2 = spdlog::create("l2"); - REQUIRE(l1->level() == spdlog::log_level::trace); - REQUIRE(l2->level() == spdlog::log_level::info); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + REQUIRE(l1->log_level() == spdlog::level::trace); + REQUIRE(l2->log_level() == spdlog::level::info); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } TEST_CASE("level-not-set-test4", "[cfg]") @@ -152,9 +152,9 @@ TEST_CASE("level-not-set-test4", "[cfg]") auto l1 = spdlog::create("l1"); auto l2 = spdlog::create("l2"); - REQUIRE(l1->level() == spdlog::log_level::trace); - REQUIRE(l2->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::warn); + REQUIRE(l1->log_level() == spdlog::level::trace); + REQUIRE(l2->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::warn); } TEST_CASE("level-not-set-test5", "[cfg]") @@ -168,9 +168,9 @@ TEST_CASE("level-not-set-test5", "[cfg]") auto l1 = spdlog::create("l1"); auto l2 = spdlog::create("l2"); - REQUIRE(l1->level() == spdlog::log_level::warn); - REQUIRE(l2->level() == spdlog::log_level::warn); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::warn); + REQUIRE(l1->log_level() == spdlog::level::warn); + REQUIRE(l2->log_level() == spdlog::level::warn); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::warn); } TEST_CASE("restore-to-default", "[cfg]") @@ -179,5 +179,5 @@ TEST_CASE("restore-to-default", "[cfg]") spdlog::drop("l2"); const char *argv[] = {"ignore", "SPDLOG_LEVEL=info"}; load_argv_levels(2, argv); - REQUIRE(spdlog::default_logger()->level() == spdlog::log_level::info); + REQUIRE(spdlog::default_logger()->log_level() == spdlog::level::info); } diff --git a/tests/test_daily_logger.cpp b/tests/test_daily_logger.cpp index 78602fed..82f28941 100644 --- a/tests/test_daily_logger.cpp +++ b/tests/test_daily_logger.cpp @@ -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) { using spdlog::log_clock; - spdlog::details::log_msg msg{"test", spdlog::log_level::info, "Hello Message"}; + spdlog::details::log_msg msg{"test", spdlog::level::info, "Hello Message"}; msg.time = log_clock::now() + offset; return msg; } diff --git a/tests/test_dup_filter.cpp b/tests/test_dup_filter.cpp index 9b5b3921..8ae2ee60 100644 --- a/tests/test_dup_filter.cpp +++ b/tests/test_dup_filter.cpp @@ -13,7 +13,7 @@ TEST_CASE("dup_filter_test1", "[dup_filter_sink]") for (int i = 0; i < 10; i++) { - 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"}); } 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++) { - 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"}); 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++) { - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message1"}); - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message2"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"}); } REQUIRE(test_sink->msg_counter() == 20); @@ -64,9 +64,9 @@ TEST_CASE("dup_filter_test4", "[dup_filter_sink]") auto test_sink = std::make_shared(); dup_sink.add_sink(test_sink); - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"}); std::this_thread::sleep_for(std::chrono::milliseconds(50)); - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"}); REQUIRE(test_sink->msg_counter() == 2); } @@ -80,10 +80,10 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]") test_sink->set_pattern("%v"); dup_sink.add_sink(test_sink); - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_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::log_level::info, "message1"}); - dup_sink.log(spdlog::details::log_msg{"test", spdlog::log_level::info, "message2"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); + dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "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.."); diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index ae764f40..0f6ee348 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -45,7 +45,7 @@ TEST_CASE("custom_error_handler", "[errors]") prepare_logdir(); spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG); auto logger = spdlog::create("logger", filename, true); - logger->flush_on(spdlog::log_level::info); + logger->flush_on(spdlog::level::info); logger->set_error_handler([=](const std::string &) { throw custom_ex(); }); logger->info("Good message #1"); diff --git a/tests/test_eventlog.cpp b/tests/test_eventlog.cpp index 1d54d839..5253c5a7 100644 --- a/tests/test_eventlog.cpp +++ b/tests/test_eventlog.cpp @@ -56,7 +56,7 @@ TEST_CASE("eventlog", "[eventlog]") auto test_sink = std::make_shared(TEST_SOURCE); spdlog::logger test_logger("eventlog", test_sink); - test_logger.set_level(log_level::trace); + test_logger.set_level(level::trace); test_sink->set_pattern("%v"); diff --git a/tests/test_file_logging.cpp b/tests/test_file_logging.cpp index 4844b0a2..7a7119ad 100644 --- a/tests/test_file_logging.cpp +++ b/tests/test_file_logging.cpp @@ -30,8 +30,8 @@ TEST_CASE("flush_on", "[flush_on]") auto logger = spdlog::create("logger", filename); logger->set_pattern("%v"); - logger->set_level(spdlog::log_level::trace); - logger->flush_on(spdlog::log_level::info); + logger->set_level(spdlog::level::trace); + logger->flush_on(spdlog::level::info); logger->trace("Should not be flushed"); REQUIRE(count_lines(SIMPLE_LOG) == 0); diff --git a/tests/test_log_level.cpp b/tests/test_log_level.cpp new file mode 100644 index 00000000..57d1a9db --- /dev/null +++ b/tests/test_log_level.cpp @@ -0,0 +1,102 @@ +#include "includes.h" +#include "test_sink.h" +#include +#include + +TEST_CASE("test_default_level", "[log_level]") +{ + auto test_sink = std::make_shared(); + REQUIRE(test_sink->log_level() == spdlog::level::trace); + spdlog::logger logger("test-level", test_sink); + REQUIRE(test_sink->log_level() == spdlog::level::trace);\ + REQUIRE(logger.log_level() == spdlog::level::info); +} + + +// test that logger log only messages with level bigger or equal to its level +void test_logger_level(spdlog::level level); +TEST_CASE("test_logger_levels", "[log_level]") +{ + for (size_t i = 0; i < spdlog::levels_count; i++) + { + auto level = static_cast(i); + test_logger_level(level); + } +} + + +// test that logger log all messages with level bigger or equal to its level +void test_sink_level(spdlog::level level); +TEST_CASE("test_sink_levels", "[log_level]") +{ + for (size_t i = 0; i < spdlog::levels_count; i++) + { + auto level = static_cast(i); + test_sink_level(level); + } +} + + +// +// test helpers to check that logger/sink displays only messages with level bigger or equal to its level +// +auto get_expected_messages(spdlog::level level) +{ + // expected messages for each level + static const std::map> messages = { + {spdlog::level::trace, {"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}}, + {spdlog::level::debug, {"debug hello", "info hello", "warning hello", "error hello", "critical hello"}}, + {spdlog::level::info, {"info hello", "warning hello", "error hello", "critical hello"}}, + {spdlog::level::warn, {"warning hello", "error hello", "critical hello"}}, + {spdlog::level::err, {"error hello", "critical hello"}}, + {spdlog::level::critical, {"critical hello"}}, + {spdlog::level::off, {}}, + {spdlog::level::n_levels, {}} + }; + return messages.at(level); +} + +void test_logger_level(spdlog::level level) +{ + auto test_sink = std::make_shared(); + spdlog::logger logger("test-level", test_sink); + logger.set_level(level); + logger.set_pattern("%l %v"); + REQUIRE(logger.log_level() == level); + REQUIRE(test_sink->log_level() == spdlog::level::trace); + + logger.trace("hello"); + logger.debug("hello"); + logger.info("hello"); + logger.warn("hello"); + logger.error("hello"); + logger.critical("hello"); + + auto lines = test_sink->lines(); + REQUIRE(lines == get_expected_messages(level)); +} + + +// test that sink displays all messages with level bigger or equal to its level +void test_sink_level(spdlog::level level) +{ + auto test_sink = std::make_shared(); + spdlog::logger logger("test-level", test_sink); + logger.set_level(spdlog::level::trace); + test_sink->set_level(level); + + REQUIRE(logger.log_level() == spdlog::level::trace); + REQUIRE(test_sink->log_level() == level); + + logger.set_pattern("%l %v"); + + logger.trace("hello"); + logger.debug("hello"); + logger.info("hello"); + logger.warn("hello"); + logger.error("hello"); + logger.critical("hello"); + + auto lines = test_sink->lines(); + REQUIRE(lines == get_expected_messages(level)); +} \ No newline at end of file diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp index b82e40cd..36537958 100644 --- a/tests/test_macros.cpp +++ b/tests/test_macros.cpp @@ -18,7 +18,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]") auto logger = spdlog::create("logger", filename); logger->set_pattern("%v"); - logger->set_level(spdlog::log_level::trace); + logger->set_level(spdlog::level::trace); SPDLOG_LOGGER_TRACE(logger, "Test message 1"); SPDLOG_LOGGER_DEBUG(logger, "Test message 2"); diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index fcf9de6a..606e3fe7 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -2,7 +2,7 @@ #include "test_sink.h" template -std::string log_info(const T &what, spdlog::log_level logger_level = spdlog::log_level::info) +std::string log_info(const T &what, spdlog::level logger_level = spdlog::level::info) { std::ostringstream oss; @@ -29,46 +29,46 @@ TEST_CASE("basic_logging ", "[basic_logging]") TEST_CASE("log_levels", "[log_levels]") { - REQUIRE(log_info("Hello", spdlog::log_level::err).empty()); - REQUIRE(log_info("Hello", spdlog::log_level::critical).empty()); - REQUIRE(log_info("Hello", spdlog::log_level::info) == "Hello"); - REQUIRE(log_info("Hello", spdlog::log_level::debug) == "Hello"); - REQUIRE(log_info("Hello", spdlog::log_level::trace) == "Hello"); + REQUIRE(log_info("Hello", spdlog::level::err).empty()); + REQUIRE(log_info("Hello", spdlog::level::critical).empty()); + REQUIRE(log_info("Hello", spdlog::level::info) == "Hello"); + REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello"); + REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello"); } TEST_CASE("level_to_string_view", "[convert_to_string_view]") { - REQUIRE(spdlog::to_string_view(spdlog::log_level::trace) == "trace"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::debug) == "debug"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::info) == "info"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::warn) == "warning"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::err) == "error"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::critical) == "critical"); - REQUIRE(spdlog::to_string_view(spdlog::log_level::off) == "off"); + REQUIRE(spdlog::to_string_view(spdlog::level::trace) == "trace"); + REQUIRE(spdlog::to_string_view(spdlog::level::debug) == "debug"); + REQUIRE(spdlog::to_string_view(spdlog::level::info) == "info"); + REQUIRE(spdlog::to_string_view(spdlog::level::warn) == "warning"); + REQUIRE(spdlog::to_string_view(spdlog::level::err) == "error"); + REQUIRE(spdlog::to_string_view(spdlog::level::critical) == "critical"); + REQUIRE(spdlog::to_string_view(spdlog::level::off) == "off"); } TEST_CASE("to_short_c_str", "[convert_to_short_c_str]") { - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::trace)) == "T"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::debug)) == "D"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::info)) == "I"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::warn)) == "W"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::err)) == "E"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::critical)) == "C"); - REQUIRE(std::string(spdlog::to_short_c_str(spdlog::log_level::off)) == "O"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::trace)) == "T"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::debug)) == "D"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::info)) == "I"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::warn)) == "W"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::err)) == "E"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::critical)) == "C"); + REQUIRE(std::string(spdlog::to_short_c_str(spdlog::level::off)) == "O"); } TEST_CASE("to_level_enum", "[convert_to_level_enum]") { - REQUIRE(spdlog::level_from_str("trace") == spdlog::log_level::trace); - REQUIRE(spdlog::level_from_str("debug") == spdlog::log_level::debug); - REQUIRE(spdlog::level_from_str("info") == spdlog::log_level::info); - REQUIRE(spdlog::level_from_str("warning") == spdlog::log_level::warn); - REQUIRE(spdlog::level_from_str("warn") == spdlog::log_level::warn); - REQUIRE(spdlog::level_from_str("error") == spdlog::log_level::err); - REQUIRE(spdlog::level_from_str("critical") == spdlog::log_level::critical); - REQUIRE(spdlog::level_from_str("off") == spdlog::log_level::off); - REQUIRE(spdlog::level_from_str("null") == spdlog::log_level::off); + REQUIRE(spdlog::level_from_str("trace") == spdlog::level::trace); + REQUIRE(spdlog::level_from_str("debug") == spdlog::level::debug); + REQUIRE(spdlog::level_from_str("info") == spdlog::level::info); + REQUIRE(spdlog::level_from_str("warning") == spdlog::level::warn); + REQUIRE(spdlog::level_from_str("warn") == spdlog::level::warn); + REQUIRE(spdlog::level_from_str("error") == spdlog::level::err); + REQUIRE(spdlog::level_from_str("critical") == spdlog::level::critical); + REQUIRE(spdlog::level_from_str("off") == spdlog::level::off); + REQUIRE(spdlog::level_from_str("null") == spdlog::level::off); } TEST_CASE("periodic flush", "[periodic_flush]") @@ -94,7 +94,7 @@ TEST_CASE("clone-logger", "[clone]") REQUIRE(cloned->name() == "clone"); REQUIRE(logger->sinks() == cloned->sinks()); - REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->log_level() == cloned->log_level()); REQUIRE(logger->flush_level() == cloned->flush_level()); logger->info("Some message 1"); cloned->info("Some message 2"); @@ -117,7 +117,7 @@ TEST_CASE("clone async", "[clone]") REQUIRE(cloned->name() == "clone"); REQUIRE(logger->sinks() == cloned->sinks()); - REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->log_level() == cloned->log_level()); REQUIRE(logger->flush_level() == cloned->flush_level()); logger->info("Some message 1"); @@ -140,7 +140,7 @@ TEST_CASE("default logger API", "[default logger]") spdlog::set_default_logger(std::make_shared("oss", oss_sink)); spdlog::set_pattern("*** %v"); - spdlog::default_logger()->set_level(spdlog::log_level::trace); + spdlog::default_logger()->set_level(spdlog::level::trace); spdlog::trace("hello trace"); 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)); oss.str(""); - spdlog::set_level(spdlog::log_level::info); + spdlog::set_level(spdlog::level::info); spdlog::debug("should not be logged"); REQUIRE(oss.str().empty()); spdlog::drop_all(); diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index 9f202e7d..e6edfca1 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -11,7 +11,7 @@ static std::string log_to_str(const std::string &msg, const Args &...args) std::ostringstream oss; auto oss_sink = std::make_shared(oss); spdlog::logger oss_logger("pattern_tester", oss_sink); - oss_logger.set_level(spdlog::log_level::info); + oss_logger.set_level(spdlog::level::info); oss_logger.set_formatter(std::unique_ptr(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"); memory_buf_t formatted; std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, spdlog::string_view_t(buf.data(), buf.size())); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size())); formatter->format(msg, formatted); REQUIRE(msg.color_range_start == 0); REQUIRE(msg.color_range_end == 5); @@ -79,7 +79,7 @@ TEST_CASE("color range test2", "[pattern_formatter]") { auto formatter = std::make_shared("%^%$", spdlog::pattern_time_type::local, "\n"); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, ""); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, ""); memory_buf_t formatted; formatter->format(msg, formatted); REQUIRE(msg.color_range_start == 0); @@ -91,7 +91,7 @@ TEST_CASE("color range test3", "[pattern_formatter]") { auto formatter = std::make_shared("%^***%$"); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); memory_buf_t formatted; formatter->format(msg, formatted); REQUIRE(msg.color_range_start == 0); @@ -102,7 +102,7 @@ TEST_CASE("color range test4", "[pattern_formatter]") { auto formatter = std::make_shared("XX%^YYY%$", spdlog::pattern_time_type::local, "\n"); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); memory_buf_t formatted; formatter->format(msg, formatted); @@ -115,7 +115,7 @@ TEST_CASE("color range test5", "[pattern_formatter]") { auto formatter = std::make_shared("**%^"); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); memory_buf_t formatted; formatter->format(msg, formatted); REQUIRE(msg.color_range_start == 2); @@ -126,7 +126,7 @@ TEST_CASE("color range test6", "[pattern_formatter]") { auto formatter = std::make_shared("**%$"); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "ignored"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored"); memory_buf_t formatted; formatter->format(msg, formatted); REQUIRE(msg.color_range_start == 0); @@ -236,11 +236,11 @@ TEST_CASE("padding_truncate_funcname", "[pattern_formatter]") auto formatter = std::unique_ptr(new spdlog::pattern_formatter(pattern)); test_sink.set_formatter(std::move(formatter)); - spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::log_level::info, "message"}; + spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg1); REQUIRE(test_sink.lines()[0] == "message [ func]"); - spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::log_level::info, "message"}; + spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg2); REQUIRE(test_sink.lines()[1] == "message [funct]"); } @@ -253,11 +253,11 @@ TEST_CASE("padding_funcname", "[pattern_formatter]") auto formatter = std::unique_ptr(new spdlog::pattern_formatter(pattern)); test_sink.set_formatter(std::move(formatter)); - spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::log_level::info, "message"}; + spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg1); REQUIRE(test_sink.lines()[0] == "message [ func]"); - spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger", spdlog::log_level::info, "message"}; + spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger", spdlog::level::info, "message"}; test_sink.log(msg2); REQUIRE(test_sink.lines()[1] == "message [func567890123]"); } @@ -267,7 +267,7 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]") auto formatter_1 = std::make_shared(); auto formatter_2 = formatter_1->clone(); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); memory_buf_t formatted_1; memory_buf_t formatted_2; @@ -282,7 +282,7 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]") auto formatter_1 = std::make_shared("%+"); auto formatter_2 = formatter_1->clone(); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); memory_buf_t formatted_1; memory_buf_t formatted_2; @@ -297,7 +297,7 @@ TEST_CASE("clone-formatter", "[pattern_formatter]") auto formatter_1 = std::make_shared("%D %X [%] [%n] %v"); auto formatter_2 = formatter_1->clone(); std::string logger_name = "test"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); memory_buf_t formatted_1; memory_buf_t formatted_2; @@ -313,7 +313,7 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]") auto formatter_1 = std::make_shared("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n"); auto formatter_2 = formatter_1->clone(); std::string logger_name = "test2"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); memory_buf_t formatted_1; memory_buf_t formatted_2; @@ -364,7 +364,7 @@ TEST_CASE("clone-custom_formatter", "[pattern_formatter]") formatter_1->add_flag('t', "custom_output").set_pattern("[%n] [%t] %v"); auto formatter_2 = formatter_1->clone(); std::string logger_name = "logger-name"; - spdlog::details::log_msg msg(logger_name, spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message"); memory_buf_t formatted_1; memory_buf_t formatted_2; @@ -393,7 +393,7 @@ TEST_CASE("short filename formatter-1", "[pattern_formatter]") memory_buf_t formatted; std::string logger_name = "logger-name"; spdlog::source_loc source_loc{test_path, 123, "some_func()"}; - spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello"); + spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); formatter.format(msg, formatted); REQUIRE(to_string_view(formatted) == "myfile.cpp"); @@ -405,7 +405,7 @@ TEST_CASE("short filename formatter-2", "[pattern_formatter]") memory_buf_t formatted; std::string logger_name = "logger-name"; spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"}; - spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello"); + spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); formatter.format(msg, formatted); REQUIRE(to_string_view(formatted) == "myfile.cpp:123"); @@ -417,7 +417,7 @@ TEST_CASE("short filename formatter-3", "[pattern_formatter]") memory_buf_t formatted; std::string logger_name = "logger-name"; spdlog::source_loc source_loc{"", 123, "some_func()"}; - spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello"); + spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); formatter.format(msg, formatted); REQUIRE(to_string_view(formatted) == " Hello"); @@ -429,7 +429,7 @@ TEST_CASE("full filename formatter", "[pattern_formatter]") memory_buf_t formatted; std::string logger_name = "logger-name"; spdlog::source_loc source_loc{test_path, 123, "some_func()"}; - spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::log_level::info, "Hello"); + spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello"); formatter.format(msg, formatted); REQUIRE(to_string_view(formatted) == test_path); @@ -442,7 +442,7 @@ TEST_CASE("custom flags", "[pattern_formatter]") memory_buf_t formatted; - spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); 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; - spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); 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('t', "throw_me").add_flag('u', "custom2").set_pattern("[%n] [%t] [%u] %v"); memory_buf_t formatted; - spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); 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; - spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); REQUIRE(to_string_view(formatted) == "0:00AM> some message\n"); } @@ -494,7 +494,7 @@ TEST_CASE("override need_localtime", "[pattern_formatter]") << "> some message\n"; memory_buf_t formatted; - spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::log_level::info, "some message"); + spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message"); formatter->format(msg, formatted); REQUIRE(to_string_view(formatted) == oss.str()); } diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp index 89baa077..3dc67e86 100644 --- a/tests/test_registry.cpp +++ b/tests/test_registry.cpp @@ -99,8 +99,8 @@ TEST_CASE("set_default_logger(nullptr)", "[registry]") TEST_CASE("disable automatic registration", "[registry]") { // set some global parameters - spdlog::log_level log_level = spdlog::log_level::warn; - spdlog::set_level(log_level); + spdlog::level level = spdlog::level::warn; + spdlog::set_level(level); // but disable automatic registration spdlog::set_automatic_registration(false); auto logger1 = spdlog::create(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59); @@ -109,8 +109,8 @@ TEST_CASE("disable automatic registration", "[registry]") REQUIRE_FALSE(spdlog::get(tested_logger_name)); REQUIRE_FALSE(spdlog::get(tested_logger_name2)); // but make sure they are still initialized according to global defaults - REQUIRE(logger1->level() == log_level); - REQUIRE(logger2->level() == log_level); - spdlog::set_level(spdlog::log_level::info); + REQUIRE(logger1->log_level() == level); + REQUIRE(logger2->log_level() == level); + spdlog::set_level(spdlog::level::info); spdlog::set_automatic_registration(true); } diff --git a/tests/test_stdout_api.cpp b/tests/test_stdout_api.cpp index c07c5471..a6bd5874 100644 --- a/tests/test_stdout_api.cpp +++ b/tests/test_stdout_api.cpp @@ -8,7 +8,7 @@ TEST_CASE("stdout_st", "[stdout]") { auto l = spdlog::stdout_logger_st("test"); l->set_pattern("%+"); - l->set_level(spdlog::log_level::trace); + l->set_level(spdlog::level::trace); l->trace("Test stdout_st"); spdlog::drop_all(); } @@ -17,7 +17,7 @@ TEST_CASE("stdout_mt", "[stdout]") { auto l = spdlog::stdout_logger_mt("test"); l->set_pattern("%+"); - l->set_level(spdlog::log_level::debug); + l->set_level(spdlog::level::debug); l->debug("Test stdout_mt"); spdlog::drop_all(); } @@ -54,7 +54,7 @@ TEST_CASE("stdout_color_mt", "[stdout]") { auto l = spdlog::stdout_color_mt("test"); l->set_pattern("%+"); - l->set_level(spdlog::log_level::trace); + l->set_level(spdlog::level::trace); l->trace("Test stdout_color_mt"); spdlog::drop_all(); } @@ -63,7 +63,7 @@ TEST_CASE("stderr_color_st", "[stderr]") { auto l = spdlog::stderr_color_st("test"); l->set_pattern("%+"); - l->set_level(spdlog::log_level::debug); + l->set_level(spdlog::level::debug); l->debug("Test stderr_color_st"); spdlog::drop_all(); } diff --git a/tests/test_systemd.cpp b/tests/test_systemd.cpp index 141d364a..8688f41d 100644 --- a/tests/test_systemd.cpp +++ b/tests/test_systemd.cpp @@ -5,7 +5,7 @@ TEST_CASE("systemd", "[all]") { auto systemd_sink = std::make_shared(); spdlog::logger logger("spdlog_systemd_test", systemd_sink); - logger.set_level(spdlog::log_level::trace); + logger.set_level(spdlog::level::trace); logger.trace("test spdlog trace"); logger.debug("test spdlog debug"); SPDLOG_LOGGER_INFO((&logger), "test spdlog info"); diff --git a/tests/test_time_point.cpp b/tests/test_time_point.cpp index b38b1825..bacff69a 100644 --- a/tests/test_time_point.cpp +++ b/tests/test_time_point.cpp @@ -15,15 +15,15 @@ TEST_CASE("time_point1", "[time_point log_msg]") test_sink->set_delay(std::chrono::milliseconds(10)); for (int i = 0; i < 5; i++) { - spdlog::details::log_msg msg{tp, source, "test_logger", spdlog::log_level::info, "message"}; + spdlog::details::log_msg msg{tp, source, "test_logger", spdlog::level::info, "message"}; test_sink->log(msg); } - logger.log(tp, source, spdlog::log_level::info, "formatted message"); - logger.log(tp, source, spdlog::log_level::info, "formatted message"); - logger.log(tp, source, spdlog::log_level::info, "formatted message"); - logger.log(tp, source, spdlog::log_level::info, "formatted message"); - logger.log(source, spdlog::log_level::info, "formatted message"); // last line has different time_point + logger.log(tp, source, spdlog::level::info, "formatted message"); + logger.log(tp, source, spdlog::level::info, "formatted message"); + logger.log(tp, source, spdlog::level::info, "formatted message"); + logger.log(tp, source, spdlog::level::info, "formatted message"); + logger.log(source, spdlog::level::info, "formatted message"); // last line has different time_point // now the real test... that the times are the same. std::vector lines = test_sink->lines();