Merge branch 'gabime:v1.x' into feature-source_location

pull/2690/head
M. Galib Uludag 2 years ago committed by GitHub
commit 8bf79cfa80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,27 +26,35 @@ SPDLOG_INLINE spdlog::async_logger::async_logger(
// send the log message to the thread pool
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
{
if (auto pool_ptr = thread_pool_.lock())
SPDLOG_TRY
{
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
}
else
{
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
if (auto pool_ptr = thread_pool_.lock())
{
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
}
else
{
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
}
}
SPDLOG_LOGGER_CATCH(msg.source)
}
// send flush request to the thread pool
SPDLOG_INLINE void spdlog::async_logger::flush_()
{
if (auto pool_ptr = thread_pool_.lock())
SPDLOG_TRY
{
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
}
else
{
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
if (auto pool_ptr = thread_pool_.lock())
{
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
}
else
{
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
}
}
SPDLOG_LOGGER_CATCH(source_loc())
}
//

@ -248,9 +248,9 @@ SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
char date_buf[64];
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
#if defined(USING_R) && defined(R_R_H) // if in R environment
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] {%s}\n", err_counter, date_buf, name().c_str(), msg.c_str());
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str());
#else
std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] {%s}\n", err_counter, date_buf, name().c_str(), msg.c_str());
std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str());
#endif
}
}

@ -372,7 +372,7 @@ protected:
#ifdef SPDLOG_USE_STD_FORMAT
fmt_lib::vformat_to(std::back_inserter(buf), fmt, fmt_lib::make_format_args(std::forward<Args>(args)...));
#else
fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(std::forward<Args>(args)...));
fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(args...));
#endif
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));

@ -185,6 +185,14 @@ TEST_CASE("to_file multi-workers", "[async]")
logger->info("Hello message #{}", j);
}
}
require_message_count(TEST_FILENAME, messages);
}
TEST_CASE("bad_tp", "[async]")
{
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
std::shared_ptr<spdlog::details::thread_pool> const empty_tp;
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, empty_tp);
logger->info("Please throw an exception");
REQUIRE(test_sink->msg_counter() == 0);
}

@ -39,6 +39,6 @@ TEST_CASE("stopwatch2", "[stopwatch]")
auto val = std::stod(test_sink->lines()[0]);
auto diff_duration = duration_cast<std::chrono::duration<double>>(stop - start);
REQUIRE(val >= diff_duration.count());
REQUIRE(val >= (diff_duration).count() - 0.001);
REQUIRE(val <= (diff_duration + tolerance_duration).count());
}

Loading…
Cancel
Save