mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
code format
This commit is contained in:
@@ -71,7 +71,6 @@ TEST_CASE("discard policy discard_new ", "[async]") {
|
||||
auto as = std::make_shared<async_sink>(config);
|
||||
auto logger = std::make_shared<spdlog::logger>("async_logger", as);
|
||||
|
||||
|
||||
REQUIRE(as->get_config().policy == async_sink::overflow_policy::discard_new);
|
||||
REQUIRE(as->get_discard_counter() == 0);
|
||||
REQUIRE(as->get_overrun_counter() == 0);
|
||||
@@ -167,7 +166,6 @@ TEST_CASE("to_file", "[async]") {
|
||||
REQUIRE(ends_with(contents, spdlog::fmt_lib::format("Hello message #1023{}", default_eol)));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("bad_ctor", "[async]") {
|
||||
async_sink::config cfg;
|
||||
cfg.queue_size = 0;
|
||||
@@ -303,9 +301,9 @@ TEST_CASE("custom_err_handler", "[async]") {
|
||||
test_sink->set_exception(std::runtime_error("test backend exception"));
|
||||
async_sink::config config;
|
||||
config.sinks.push_back(std::move(test_sink));
|
||||
config.custom_err_handler = [&error_called](const std::string &) { error_called = true;};
|
||||
config.custom_err_handler = [&error_called](const std::string &) { error_called = true; };
|
||||
auto asink = std::make_shared<async_sink>(config);
|
||||
spdlog::logger ("async_logger", std::move(asink)).info("Test");
|
||||
spdlog::logger("async_logger", std::move(asink)).info("Test");
|
||||
// lvalue logger so will be destructed here already so all messages were processed
|
||||
REQUIRE(error_called);
|
||||
}
|
||||
@@ -334,9 +332,9 @@ TEST_CASE("wait_all", "[async]") {
|
||||
REQUIRE(elapsed < delay * 3);
|
||||
// wait enough time for all messages to be processed
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(messages * delay)));
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(-10))); // no more messages
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(0))); // no more messages
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(10))); // no more messages
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(-10))); // no more messages
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(0))); // no more messages
|
||||
REQUIRE(as->wait_all(std::chrono::milliseconds(10))); // no more messages
|
||||
}
|
||||
|
||||
// test wait_all without timeout
|
||||
|
@@ -18,7 +18,6 @@ protected:
|
||||
};
|
||||
struct custom_ex {};
|
||||
|
||||
|
||||
using namespace spdlog::sinks;
|
||||
TEST_CASE("default_error_handler", "[errors]") {
|
||||
prepare_logdir();
|
||||
@@ -36,9 +35,7 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
||||
prepare_logdir();
|
||||
auto logger = spdlog::create<basic_file_sink_mt>("test-format-error", log_filename);
|
||||
logger->flush_on(spdlog::level::info);
|
||||
logger->set_error_handler([=](const std::string & msg) {
|
||||
REQUIRE(msg == "argument not found");
|
||||
});
|
||||
logger->set_error_handler([=](const std::string &msg) { REQUIRE(msg == "argument not found"); });
|
||||
logger->info("Good message #1");
|
||||
REQUIRE_NOTHROW(logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx"));
|
||||
logger->info("Good message #2");
|
||||
|
@@ -6,9 +6,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <exception>
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/details/os.h"
|
||||
@@ -37,13 +37,9 @@ public:
|
||||
delay_ = delay;
|
||||
}
|
||||
|
||||
void set_exception(const std::runtime_error& ex) {
|
||||
exception_ptr_ = std::make_exception_ptr(ex);
|
||||
}
|
||||
void set_exception(const std::runtime_error& ex) { exception_ptr_ = std::make_exception_ptr(ex); }
|
||||
|
||||
void clear_exception() {
|
||||
exception_ptr_ = nullptr;
|
||||
}
|
||||
void clear_exception() { exception_ptr_ = nullptr; }
|
||||
|
||||
// return last output without the eol
|
||||
std::vector<std::string> lines() {
|
||||
@@ -52,7 +48,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
void sink_it_(const details::log_msg& msg) override {
|
||||
if (exception_ptr_) {
|
||||
std::rethrow_exception(exception_ptr_);
|
||||
}
|
||||
@@ -78,7 +74,7 @@ protected:
|
||||
size_t flush_counter_{0};
|
||||
std::chrono::milliseconds delay_{std::chrono::milliseconds::zero()};
|
||||
std::vector<std::string> lines_;
|
||||
std::exception_ptr exception_ptr_; // will be thrown on next log or flush if not null
|
||||
std::exception_ptr exception_ptr_; // will be thrown on next log or flush if not null
|
||||
};
|
||||
|
||||
using test_sink_mt = test_sink<std::mutex>;
|
||||
|
Reference in New Issue
Block a user