mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-01 03:35:50 +08:00
improved err_helper message while catching exceptions
Some checks failed
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 3s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 3s
Some checks failed
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 3s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 3s
This commit is contained in:
parent
a8e7527d2d
commit
35060923d9
@ -46,10 +46,10 @@ void err_helper::handle_ex(const std::string &origin, const source_loc &loc, con
|
|||||||
}
|
}
|
||||||
std::fputs(msg.c_str(), stderr);
|
std::fputs(msg.c_str(), stderr);
|
||||||
} catch (const std::exception &handler_ex) {
|
} catch (const std::exception &handler_ex) {
|
||||||
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] caught exception during error handler: %s\n", origin.c_str(),
|
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] exception during %s handler: %s\n", origin.c_str(), custom_err_handler_ ? "custom" : "default",
|
||||||
handler_ex.what());
|
handler_ex.what());
|
||||||
} catch (...) { // catch all exceptions
|
} catch (...) { // catch all exceptions
|
||||||
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] caught unknown exception during error handler\n", origin.c_str());
|
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] unknown exception during %s handler\n", origin.c_str(), custom_err_handler_ ? "custom" : "default");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ struct custom_ex {};
|
|||||||
using namespace spdlog::sinks;
|
using namespace spdlog::sinks;
|
||||||
TEST_CASE("default_error_handler", "[errors]") {
|
TEST_CASE("default_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
auto logger = spdlog::create<basic_file_sink_mt>("test-error", log_filename);
|
auto logger = spdlog::create<basic_file_sink_mt>("test-bad-format", log_filename);
|
||||||
logger->set_pattern("%v");
|
logger->set_pattern("%v");
|
||||||
logger->info(SPDLOG_FMT_RUNTIME("Test message {} {}"), 1);
|
logger->info(SPDLOG_FMT_RUNTIME("Test message {} {}"), 1);
|
||||||
logger->info("Test message {}", 2);
|
logger->info("Test message {}", 2);
|
||||||
@ -42,8 +42,36 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
|||||||
require_message_count(log_filename, 2);
|
require_message_count(log_filename, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("default_error_handler2", "[errors]") {
|
TEST_CASE("throwing_sink", "[errors]") {
|
||||||
auto logger = std::make_shared<spdlog::logger>("test-failing-sink", std::make_shared<failing_sink>());
|
auto logger = std::make_shared<spdlog::logger>("test-throwing-sink", std::make_shared<failing_sink>());
|
||||||
|
REQUIRE_NOTHROW(logger->info("Some message"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("throwing_flush", "[errors]") {
|
||||||
|
auto logger = spdlog::create<failing_sink>("test-throwing-sink");
|
||||||
|
REQUIRE_NOTHROW(logger->flush());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("throwing_error_handler", "[errors]") {
|
||||||
|
auto logger = std::make_shared<spdlog::logger>("test-throwing-error-handler", std::make_shared<failing_sink>());
|
||||||
|
logger->set_error_handler([=](const std::string &msg) {
|
||||||
|
REQUIRE(msg == log_err_msg);
|
||||||
|
throw std::runtime_error("test throw");
|
||||||
|
});
|
||||||
|
REQUIRE_NOTHROW(logger->info("Some message"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("throwing_flush_error_handler", "[errors]") {
|
||||||
|
auto logger = spdlog::create<failing_sink>("test-throwing-error-handler");
|
||||||
|
logger->set_error_handler([=](const std::string &msg) {
|
||||||
|
REQUIRE(msg == flush_err_msg);
|
||||||
|
throw std::runtime_error("test throw");
|
||||||
|
});
|
||||||
|
REQUIRE_NOTHROW(logger->flush());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("unknown_ex_from_err_handler", "[errors]") {
|
||||||
|
auto logger = std::make_shared<spdlog::logger>("test-throwing-error-handler", std::make_shared<failing_sink>());
|
||||||
logger->set_error_handler([=](const std::string &msg) {
|
logger->set_error_handler([=](const std::string &msg) {
|
||||||
REQUIRE(msg == log_err_msg);
|
REQUIRE(msg == log_err_msg);
|
||||||
throw custom_ex();
|
throw custom_ex();
|
||||||
@ -51,8 +79,8 @@ TEST_CASE("default_error_handler2", "[errors]") {
|
|||||||
REQUIRE_NOTHROW(logger->info("Some message"));
|
REQUIRE_NOTHROW(logger->info("Some message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("flush_error_handler", "[errors]") {
|
TEST_CASE("unknown_ex_from_flush_err_handler", "[errors]") {
|
||||||
auto logger = spdlog::create<failing_sink>("test-failing-sink");
|
auto logger = spdlog::create<failing_sink>("test-throwing-error-handler");
|
||||||
logger->set_error_handler([=](const std::string &msg) {
|
logger->set_error_handler([=](const std::string &msg) {
|
||||||
REQUIRE(msg == flush_err_msg);
|
REQUIRE(msg == flush_err_msg);
|
||||||
throw custom_ex();
|
throw custom_ex();
|
||||||
|
Loading…
Reference in New Issue
Block a user