Compare commits

...

3 Commits

Author SHA1 Message Date
Gabi Melman 082d6fbea9
Merge pull request #1984 from hctym1995/v1.x
Add a color-terminal type
2021-06-28 15:10:01 +03:00
zyw1995ted@163.com 37372960a8 add a color-terminal type 2021-06-28 18:12:12 +08:00
gabime 0035a0c98d Fixed dup sink compile warnings in older compilers with back_inserter 2021-06-28 12:09:39 +03:00
3 changed files with 14 additions and 8 deletions

View File

@ -415,8 +415,8 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
return true;
}
static constexpr std::array<const char *, 15> terms = {{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux",
"msys", "putty", "rxvt", "screen", "vt100", "xterm", "alacritty"}};
static constexpr std::array<const char *, 16> terms = {{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux",
"msys", "putty", "rxvt", "screen", "vt100", "xterm", "alacritty", "vt102"}};
const char *env_term_p = std::getenv("TERM");
if (env_term_p == nullptr)

View File

@ -7,7 +7,7 @@
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/log_msg.h>
#include <iterator>
#include <cstdio>
#include <mutex>
#include <string>
#include <chrono>
@ -62,11 +62,14 @@ protected:
// log the "skipped.." message
if (skip_counter_ > 0)
{
memory_buf_t buf;
fmt::format_to(buf, "Skipped {} duplicate messages..", skip_counter_);
details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf.data(), buf.size()}};
dist_sink<Mutex>::sink_it_(skipped_msg);
{
char buf[64];
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
if (msg_size > 0 && msg_size < sizeof(buf))
{
details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf, static_cast<size_t>(msg_size)}};
dist_sink<Mutex>::sink_it_(skipped_msg);
}
}
// log current message

View File

@ -77,6 +77,7 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
dup_filter_sink_mt dup_sink{std::chrono::seconds{5}};
auto test_sink = std::make_shared<test_sink_mt>();
test_sink->set_pattern("%v");
dup_sink.add_sink(test_sink);
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
@ -85,4 +86,6 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
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..");
}