From a8efa85b862736f9f53e3114399478148e5e3b7e Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 1 Oct 2023 12:20:48 +0300 Subject: [PATCH] Remove global console mutex (wip) --- include/spdlog/details/registry.h | 5 +- include/spdlog/sinks/ansicolor_sink.h | 71 ++------- include/spdlog/sinks/stdout_color_sinks.h | 2 +- include/spdlog/sinks/stdout_sinks.h | 35 ++--- include/spdlog/sinks/wincolor_sink.h | 1 - include/spdlog/spdlog.h | 1 + src/sinks/ansicolor_sink.cpp | 170 ++++++++++++---------- src/sinks/basic_file_sink.cpp | 1 - src/sinks/stdout_sinks.cpp | 62 +++----- src/sinks/wincolor_sink.cpp | 2 +- src/spdlog.cpp | 7 +- tests/test_create_dir.cpp | 2 +- tests/test_custom_callbacks.cpp | 2 +- tests/test_daily_and_rotation_loggers.cpp | 2 +- tests/test_errors.cpp | 2 +- tests/test_file_helper.cpp | 2 +- tests/test_file_logging.cpp | 2 +- tests/test_include_sinks.cpp | 2 +- tests/test_macros.cpp | 2 +- tests/test_stdout_api.cpp | 52 ++++--- 20 files changed, 198 insertions(+), 227 deletions(-) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 6f6a36a6..ff0e572c 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -27,6 +27,8 @@ class thread_pool; class SPDLOG_API registry { public: using log_levels = std::unordered_map; + + static registry &instance(); registry(const registry &) = delete; registry &operator=(const registry &) = delete; @@ -84,8 +86,6 @@ public: // set levels for all existing/future loggers. global_level can be null if should not set. void set_levels(log_levels levels, level *global_level); - static registry &instance(); - void apply_logger_env_levels(std::shared_ptr new_logger); private: @@ -94,7 +94,6 @@ private: void throw_if_exists_(const std::string &logger_name); void register_logger_(std::shared_ptr new_logger); - bool set_level_from_cfg_(logger *logger); std::mutex logger_map_mutex_, flusher_mutex_; std::recursive_mutex tp_mutex_; std::unordered_map> loggers_; diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 110b7c19..ee1fc76e 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -8,8 +8,8 @@ #include #include -#include "../details/console_globals.h" #include "../details/null_mutex.h" +#include "base_sink.h" #include "sink.h" namespace spdlog { @@ -22,91 +22,48 @@ namespace sinks { * If no color terminal detected, omit the escape codes. */ -template -class ansicolor_sink : public sink { +template +class ansicolor_sink : public base_sink { public: - using mutex_t = typename ConsoleMutex::mutex_t; ansicolor_sink(FILE *target_file, color_mode mode); - ~ansicolor_sink() override = default; - ansicolor_sink(const ansicolor_sink &other) = delete; ansicolor_sink(ansicolor_sink &&other) = delete; - ansicolor_sink &operator=(const ansicolor_sink &other) = delete; ansicolor_sink &operator=(ansicolor_sink &&other) = delete; + ~ansicolor_sink() override = default; void set_color(level color_level, string_view_t color); void set_color_mode(color_mode mode); bool should_color(); - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) final; - void set_formatter(std::unique_ptr sink_formatter) override; - - // Formatting codes - static constexpr string_view_t reset = "\033[m"; - static constexpr string_view_t bold = "\033[1m"; - static constexpr string_view_t dark = "\033[2m"; - static constexpr string_view_t underline = "\033[4m"; - static constexpr string_view_t blink = "\033[5m"; - static constexpr string_view_t reverse = "\033[7m"; - static constexpr string_view_t concealed = "\033[8m"; - static constexpr string_view_t clear_line = "\033[K"; - - // Foreground colors - static constexpr string_view_t black = "\033[30m"; - static constexpr string_view_t red = "\033[31m"; - static constexpr string_view_t green = "\033[32m"; - static constexpr string_view_t yellow = "\033[33m"; - static constexpr string_view_t blue = "\033[34m"; - static constexpr string_view_t magenta = "\033[35m"; - static constexpr string_view_t cyan = "\033[36m"; - static constexpr string_view_t white = "\033[37m"; - - /// Background colors - static constexpr string_view_t on_black = "\033[40m"; - static constexpr string_view_t on_red = "\033[41m"; - static constexpr string_view_t on_green = "\033[42m"; - static constexpr string_view_t on_yellow = "\033[43m"; - static constexpr string_view_t on_blue = "\033[44m"; - static constexpr string_view_t on_magenta = "\033[45m"; - static constexpr string_view_t on_cyan = "\033[46m"; - static constexpr string_view_t on_white = "\033[47m"; - - /// Bold colors - static constexpr string_view_t yellow_bold = "\033[33m\033[1m"; - static constexpr string_view_t red_bold = "\033[31m\033[1m"; - static constexpr string_view_t bold_on_red = "\033[1m\033[41m"; - private: + void sink_it_(const details::log_msg &msg) override; + void flush_() override; FILE *target_file_; - mutex_t &mutex_; bool should_do_colors_; - std::unique_ptr formatter_; std::array colors_; void print_ccode_(const string_view_t &color_code); void print_range_(const memory_buf_t &formatted, size_t start, size_t end); static std::string to_string_(const string_view_t &sv); }; -template -class ansicolor_stdout_sink : public ansicolor_sink { +template +class ansicolor_stdout_sink : public ansicolor_sink { public: explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); }; -template -class ansicolor_stderr_sink : public ansicolor_sink { +template +class ansicolor_stderr_sink : public ansicolor_sink { public: explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); }; -using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; -using ansicolor_stdout_sink_st = ansicolor_stdout_sink; +using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; +using ansicolor_stdout_sink_st = ansicolor_stdout_sink; -using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; -using ansicolor_stderr_sink_st = ansicolor_stderr_sink; +using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; +using ansicolor_stderr_sink_st = ansicolor_stderr_sink; } // namespace sinks } // namespace spdlog diff --git a/include/spdlog/sinks/stdout_color_sinks.h b/include/spdlog/sinks/stdout_color_sinks.h index dd90e4fb..2217ac1c 100644 --- a/include/spdlog/sinks/stdout_color_sinks.h +++ b/include/spdlog/sinks/stdout_color_sinks.h @@ -27,7 +27,7 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st; #endif } // namespace sinks -// template instantiations +// logger factory functions template std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 67b37e9c..871fc8ee 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -5,8 +5,8 @@ #include -#include "../details/console_globals.h" #include "../details/synchronous_factory.h" +#include "base_sink.h" #include "sink.h" #ifdef _WIN32 @@ -17,10 +17,9 @@ namespace spdlog { namespace sinks { -template -class stdout_sink_base : public sink { +template +class stdout_sink_base : public base_sink { public: - using mutex_t = typename ConsoleMutex::mutex_t; explicit stdout_sink_base(FILE *file); ~stdout_sink_base() override = default; @@ -30,38 +29,32 @@ public: stdout_sink_base &operator=(const stdout_sink_base &other) = delete; stdout_sink_base &operator=(stdout_sink_base &&other) = delete; - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - - void set_formatter(std::unique_ptr sink_formatter) override; - -protected: - mutex_t &mutex_; +private: FILE *file_; - std::unique_ptr formatter_; + void sink_it_(const details::log_msg &msg) override; + void flush_() override; #ifdef _WIN32 HANDLE handle_; #endif // WIN32 }; -template -class stdout_sink : public stdout_sink_base { +template +class stdout_sink : public stdout_sink_base { public: stdout_sink(); }; -template -class stderr_sink : public stdout_sink_base { +template +class stderr_sink : public stdout_sink_base { public: stderr_sink(); }; -using stdout_sink_mt = stdout_sink; -using stdout_sink_st = stdout_sink; +using stdout_sink_mt = stdout_sink; +using stdout_sink_st = stdout_sink; -using stderr_sink_mt = stderr_sink; -using stderr_sink_st = stderr_sink; +using stderr_sink_mt = stderr_sink; +using stderr_sink_st = stderr_sink; } // namespace sinks diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index b4716349..3091e47e 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -10,7 +10,6 @@ #include #include "../common.h" -#include "../details/console_globals.h" #include "../details/null_mutex.h" #include "sink.h" diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 8e4c2130..aabfe053 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "common.h" diff --git a/src/sinks/ansicolor_sink.cpp b/src/sinks/ansicolor_sink.cpp index 31ff5b4b..b0560fcf 100644 --- a/src/sinks/ansicolor_sink.cpp +++ b/src/sinks/ansicolor_sink.cpp @@ -3,17 +3,55 @@ #include "spdlog/sinks/ansicolor_sink.h" +#include + +#include "spdlog/details/null_mutex.h" #include "spdlog/details/os.h" #include "spdlog/pattern_formatter.h" +namespace { +// Formatting codes +constexpr spdlog::string_view_t reset = "\033[m"; +constexpr spdlog::string_view_t bold = "\033[1m"; +constexpr spdlog::string_view_t dark = "\033[2m"; +constexpr spdlog::string_view_t underline = "\033[4m"; +constexpr spdlog::string_view_t blink = "\033[5m"; +constexpr spdlog::string_view_t reverse = "\033[7m"; +constexpr spdlog::string_view_t concealed = "\033[8m"; +constexpr spdlog::string_view_t clear_line = "\033[K"; + +// Foreground colors +constexpr spdlog::string_view_t black = "\033[30m"; +constexpr spdlog::string_view_t red = "\033[31m"; +constexpr spdlog::string_view_t green = "\033[32m"; +constexpr spdlog::string_view_t yellow = "\033[33m"; +constexpr spdlog::string_view_t blue = "\033[34m"; +constexpr spdlog::string_view_t magenta = "\033[35m"; +constexpr spdlog::string_view_t cyan = "\033[36m"; +constexpr spdlog::string_view_t white = "\033[37m"; + +// Background colors +static constexpr spdlog::string_view_t on_black = "\033[40m"; +constexpr spdlog::string_view_t on_red = "\033[41m"; +constexpr spdlog::string_view_t on_green = "\033[42m"; +constexpr spdlog::string_view_t on_yellow = "\033[43m"; +constexpr spdlog::string_view_t on_blue = "\033[44m"; +constexpr spdlog::string_view_t on_magenta = "\033[45m"; +constexpr spdlog::string_view_t on_cyan = "\033[46m"; +constexpr spdlog::string_view_t on_white = "\033[47m"; + +// Bold colors +constexpr spdlog::string_view_t yellow_bold = "\033[33m\033[1m"; +constexpr spdlog::string_view_t red_bold = "\033[31m\033[1m"; +constexpr spdlog::string_view_t bold_on_red = "\033[1m\033[41m"; +} // namespace + namespace spdlog { namespace sinks { -template -ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) - : target_file_(target_file), - mutex_(ConsoleMutex::mutex()), - formatter_(std::make_unique()) +template +ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) + : target_file_(target_file) { set_color_mode(mode); @@ -26,63 +64,19 @@ ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) colors_.at(level_to_number(level::off)) = to_string_(reset); } -template -void ansicolor_sink::set_color(level color_level, string_view_t color) { - std::lock_guard lock(mutex_); +template +void ansicolor_sink::set_color(level color_level, string_view_t color) { + std::lock_guard lock(base_sink::mutex_); colors_.at(level_to_number(color_level)) = to_string_(color); } -template -void ansicolor_sink::log(const details::log_msg &msg) { - // Wrap the originally formatted message in color codes. - // If color is not supported in the terminal, log as is instead. - std::lock_guard lock(mutex_); - msg.color_range_start = 0; - msg.color_range_end = 0; - memory_buf_t formatted; - formatter_->format(msg, formatted); - if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { - // before color range - print_range_(formatted, 0, msg.color_range_start); - // in color range - print_ccode_(colors_.at(level_to_number(msg.log_level))); - print_range_(formatted, msg.color_range_start, msg.color_range_end); - print_ccode_(reset); - // after color range - print_range_(formatted, msg.color_range_end, formatted.size()); - } else // no color - { - print_range_(formatted, 0, formatted.size()); - } - fflush(target_file_); -} - -template -void ansicolor_sink::flush() { - std::lock_guard lock(mutex_); - fflush(target_file_); -} - -template -void ansicolor_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -void ansicolor_sink::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -template -bool ansicolor_sink::should_color() { +template +bool ansicolor_sink::should_color() { return should_do_colors_; } -template -void ansicolor_sink::set_color_mode(color_mode mode) { +template +void ansicolor_sink::set_color_mode(color_mode mode) { switch (mode) { case color_mode::always: should_do_colors_ = true; @@ -99,39 +93,67 @@ void ansicolor_sink::set_color_mode(color_mode mode) { } } -template -void ansicolor_sink::print_ccode_(const string_view_t &color_code) { +template +void ansicolor_sink::sink_it_(const details::log_msg &msg) { + // Wrap the originally formatted message in color codes. + // If color is not supported in the terminal, log as is instead. + + msg.color_range_start = 0; + msg.color_range_end = 0; + memory_buf_t formatted; + base_sink::formatter_->format(msg, formatted); + if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { + // before color range + print_range_(formatted, 0, msg.color_range_start); + // in color range + print_ccode_(colors_.at(level_to_number(msg.log_level))); + print_range_(formatted, msg.color_range_start, msg.color_range_end); + print_ccode_(reset); + // after color range + print_range_(formatted, msg.color_range_end, formatted.size()); + } else // no color + { + print_range_(formatted, 0, formatted.size()); + } + fflush(target_file_); +} + +template +void ansicolor_sink::flush_() { + fflush(target_file_); +} + +template +void ansicolor_sink::print_ccode_(const string_view_t &color_code) { fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_); } -template -void ansicolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) { +template +void ansicolor_sink::print_range_(const memory_buf_t &formatted, size_t start, size_t end) { fwrite(formatted.data() + start, sizeof(char), end - start, target_file_); } -template -std::string ansicolor_sink::to_string_(const string_view_t &sv) { +template +std::string ansicolor_sink::to_string_(const string_view_t &sv) { return {sv.data(), sv.size()}; } // ansicolor_stdout_sink -template -ansicolor_stdout_sink::ansicolor_stdout_sink(color_mode mode) - : ansicolor_sink(stdout, mode) {} +template +ansicolor_stdout_sink::ansicolor_stdout_sink(color_mode mode) + : ansicolor_sink(stdout, mode) {} // ansicolor_stderr_sink -template -ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) - : ansicolor_sink(stderr, mode) {} +template +ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) + : ansicolor_sink(stderr, mode) {} } // namespace sinks } // namespace spdlog // template instantiations -template SPDLOG_API class spdlog::sinks::ansicolor_stdout_sink; -template SPDLOG_API class spdlog::sinks::ansicolor_stdout_sink; +template SPDLOG_API class spdlog::sinks::ansicolor_stdout_sink; +template SPDLOG_API class spdlog::sinks::ansicolor_stdout_sink; -template SPDLOG_API class spdlog::sinks::ansicolor_stderr_sink; -template SPDLOG_API class spdlog::sinks::ansicolor_stderr_sink; +template SPDLOG_API class spdlog::sinks::ansicolor_stderr_sink; +template SPDLOG_API class spdlog::sinks::ansicolor_stderr_sink; diff --git a/src/sinks/basic_file_sink.cpp b/src/sinks/basic_file_sink.cpp index 98f5d7a8..2455d3ae 100644 --- a/src/sinks/basic_file_sink.cpp +++ b/src/sinks/basic_file_sink.cpp @@ -4,7 +4,6 @@ #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/common.h" -#include "spdlog/details/os.h" namespace spdlog { namespace sinks { diff --git a/src/sinks/stdout_sinks.cpp b/src/sinks/stdout_sinks.cpp index d83a70ff..d740a3a8 100644 --- a/src/sinks/stdout_sinks.cpp +++ b/src/sinks/stdout_sinks.cpp @@ -26,11 +26,9 @@ namespace spdlog { namespace sinks { -template -stdout_sink_base::stdout_sink_base(FILE *file) - : mutex_(ConsoleMutex::mutex()), - file_(file), - formatter_(std::make_unique()) { +template +stdout_sink_base::stdout_sink_base(FILE *file) + : file_(file) { #ifdef _WIN32 // get windows handle from the FILE* object @@ -45,15 +43,15 @@ stdout_sink_base::stdout_sink_base(FILE *file) #endif // WIN32 } -template -void stdout_sink_base::log(const details::log_msg &msg) { +template +void stdout_sink_base::sink_it_(const details::log_msg &msg) { #ifdef _WIN32 if (handle_ == INVALID_HANDLE_VALUE) { return; } - std::lock_guard lock(mutex_); + memory_buf_t formatted; - formatter_->format(msg, formatted); + base_sink::formatter_->formatter_->format(msg, formatted); auto size = static_cast(formatted.size()); DWORD bytes_written = 0; bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0; @@ -62,42 +60,27 @@ void stdout_sink_base::log(const details::log_msg &msg) { std::to_string(::GetLastError())); } #else - std::lock_guard lock(mutex_); memory_buf_t formatted; - formatter_->format(msg, formatted); + base_sink::formatter_->format(msg, formatted); ::fwrite(formatted.data(), sizeof(char), formatted.size(), file_); #endif // WIN32 ::fflush(file_); // flush every line to terminal } -template -void stdout_sink_base::flush() { - std::lock_guard lock(mutex_); +template +void stdout_sink_base::flush_() { fflush(file_); } -template -void stdout_sink_base::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -void stdout_sink_base::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - // stdout sink -template -stdout_sink::stdout_sink() - : stdout_sink_base(stdout) {} +template +stdout_sink::stdout_sink() + : stdout_sink_base(stdout) {} // stderr sink -template -stderr_sink::stderr_sink() - : stdout_sink_base(stderr) {} +template +stderr_sink::stderr_sink() + : stdout_sink_base(stderr) {} } // namespace sinks @@ -124,13 +107,12 @@ std::shared_ptr stderr_logger_st(const std::string &logger_name) { } // namespace spdlog // template instantiations for stdout/stderr loggers -#include "spdlog/details/console_globals.h" -template class SPDLOG_API spdlog::sinks::stdout_sink_base; -template class SPDLOG_API spdlog::sinks::stdout_sink_base; -template class SPDLOG_API spdlog::sinks::stdout_sink; -template class SPDLOG_API spdlog::sinks::stdout_sink; -template class SPDLOG_API spdlog::sinks::stderr_sink; -template class SPDLOG_API spdlog::sinks::stderr_sink; +template class SPDLOG_API spdlog::sinks::stdout_sink_base; +template class SPDLOG_API spdlog::sinks::stdout_sink_base; +template class SPDLOG_API spdlog::sinks::stdout_sink; +template class SPDLOG_API spdlog::sinks::stdout_sink; +template class SPDLOG_API spdlog::sinks::stderr_sink; +template class SPDLOG_API spdlog::sinks::stderr_sink; // template instantiations for stdout/stderr factory functions #include "spdlog/async.h" diff --git a/src/sinks/wincolor_sink.cpp b/src/sinks/wincolor_sink.cpp index 60669971..b48209b4 100644 --- a/src/sinks/wincolor_sink.cpp +++ b/src/sinks/wincolor_sink.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) #ifdef _WIN32 -// clang-format off + // clang-format off #include "spdlog/details/windows_include.h" #include "spdlog/sinks/wincolor_sink.h" #include "spdlog/common.h" diff --git a/src/spdlog.cpp b/src/spdlog.cpp index 47551f01..51e21ff2 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -3,8 +3,12 @@ #include "spdlog/spdlog.h" +#include + #include "spdlog/common.h" +#include "spdlog/logger.h" #include "spdlog/pattern_formatter.h" +#include "spdlog/sinks/stdout_color_sinks.h" namespace spdlog { @@ -22,7 +26,7 @@ void set_formatter(std::unique_ptr formatter) { void set_pattern(std::string pattern, pattern_time_type time_type) { set_formatter( - std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); + std::make_unique(std::move(pattern), time_type)); } level get_level() { return default_logger_raw()->log_level(); } @@ -68,5 +72,4 @@ void set_default_logger(std::shared_ptr default_logger) { void apply_logger_env_levels(std::shared_ptr logger) { details::registry::instance().apply_logger_env_levels(std::move(logger)); } - } // namespace spdlog diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index f88825b0..c60606ea 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" diff --git a/tests/test_custom_callbacks.cpp b/tests/test_custom_callbacks.cpp index 33c7be42..78e4828c 100644 --- a/tests/test_custom_callbacks.cpp +++ b/tests/test_custom_callbacks.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" #include "spdlog/async.h" diff --git a/tests/test_daily_and_rotation_loggers.cpp b/tests/test_daily_and_rotation_loggers.cpp index 15336a6e..f368fdc1 100644 --- a/tests/test_daily_and_rotation_loggers.cpp +++ b/tests/test_daily_and_rotation_loggers.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" #include "spdlog/sinks/daily_file_sink.h" diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 4729123b..448cb7b2 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index c3d73d0d..75578be3 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" #include "spdlog/sinks/rotating_file_sink.h" diff --git a/tests/test_file_logging.cpp b/tests/test_file_logging.cpp index c0abd34e..3ba70dba 100644 --- a/tests/test_file_logging.cpp +++ b/tests/test_file_logging.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" #include "spdlog/sinks/basic_file_sink.h" diff --git a/tests/test_include_sinks.cpp b/tests/test_include_sinks.cpp index dc00d262..ec3a17a9 100644 --- a/tests/test_include_sinks.cpp +++ b/tests/test_include_sinks.cpp @@ -14,8 +14,8 @@ #include "spdlog/sinks/udp_sink.h" #ifdef _WIN32 - #include "spdlog/sinks/win_eventlog_sink.h" #include "spdlog/sinks/msvc_sink.h" + #include "spdlog/sinks/win_eventlog_sink.h" #else #include "spdlog/sinks/syslog_sink.h" #endif diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp index 4ab49576..95c7ec40 100644 --- a/tests/test_macros.cpp +++ b/tests/test_macros.cpp @@ -1,6 +1,6 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" diff --git a/tests/test_stdout_api.cpp b/tests/test_stdout_api.cpp index 07658989..92feb42f 100644 --- a/tests/test_stdout_api.cpp +++ b/tests/test_stdout_api.cpp @@ -1,48 +1,59 @@ /* * This content is released under the MIT License as specified in - * https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE + * https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE */ #include "includes.h" #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_sinks.h" + TEST_CASE("stdout_st", "[stdout]") { + spdlog::set_pattern("%+"); auto l = spdlog::stdout_logger_st("test"); - l->set_pattern("%+"); l->set_level(spdlog::level::trace); l->trace("Test stdout_st"); - spdlog::drop_all(); -} - -TEST_CASE("stdout_mt", "[stdout]") { - auto l = spdlog::stdout_logger_mt("test"); - l->set_pattern("%+"); - l->set_level(spdlog::level::debug); - l->debug("Test stdout_mt"); + l->debug("Test stdout_st"); + l->info("Test stdout_st"); + l->warn("Test stdout_st"); + l->error("Test stdout_st"); + l->critical("Test stdout_st"); spdlog::drop_all(); } TEST_CASE("stderr_st", "[stderr]") { auto l = spdlog::stderr_logger_st("test"); - l->set_pattern("%+"); + l->set_level(spdlog::level::trace); + l->trace("Test stderr_st"); + l->debug("Test stderr_st"); l->info("Test stderr_st"); + l->warn("Test stderr_st"); + l->error("Test stderr_st"); + l->critical("Test stderr_st"); spdlog::drop_all(); } +TEST_CASE("stdout_mt", "[stdout]") { + auto sink = std::make_shared(); + spdlog::logger logger("logger", sink); + logger.debug("Test stdout_mt should not be displayed !!!!"); +} + TEST_CASE("stderr_mt", "[stderr]") { - auto l = spdlog::stderr_logger_mt("test"); - l->set_pattern("%+"); - l->info("Test stderr_mt"); - l->warn("Test stderr_mt"); - l->error("Test stderr_mt"); - l->critical("Test stderr_mt"); - spdlog::drop_all(); + auto sink = std::make_shared(); + spdlog::logger logger("logger", sink); + logger.debug("Test stderr_mt should not be displayed !!!!"); } // color loggers TEST_CASE("stdout_color_st", "[stdout]") { auto l = spdlog::stdout_color_st("test"); l->set_pattern("%+"); + l->set_level(spdlog::level::trace); + l->trace("Test stdout_color_st"); + l->debug("Test stdout_color_st"); l->info("Test stdout_color_st"); + l->warn("Test stdout_color_st"); + l->error("Test stdout_color_st"); + l->critical("Test stdout_color_st"); spdlog::drop_all(); } @@ -51,6 +62,11 @@ TEST_CASE("stdout_color_mt", "[stdout]") { l->set_pattern("%+"); l->set_level(spdlog::level::trace); l->trace("Test stdout_color_mt"); + l->debug("Test stdout_color_mt"); + l->info("Test stdout_color_mt"); + l->warn("Test stdout_color_mt"); + l->error("Test stdout_color_mt"); + l->critical("Test stdout_color_mt"); spdlog::drop_all(); }