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