Spdlog will not throw exceptions while logging (since version 39cdd08).

It might throw during the construction logger or sink, because it is considered fatal.

If an error happens during logging, the library will print an error message to stderr. To avoid flooding the screen with error messages, the rate is limited per logger to 1 message/minute.

This behaviour can be changed by calling spdlog::set_error_handler(new_handler_fun) or logger->set_error_handler(new_handler_fun):

Globally change the error handler:

    spdlog::set_error_handler([](const std::string& msg) {
        std::cerr << "my err handler: " << msg << std::endl;

For a specific logger:

    critical_logger->set_error_handler([](const std::string& msg) {
        throw std::runtime_error(msg);

The default error handler

_default_err_handler will use this to print error

    fmt::print(stderr, "[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, name(), msg);

Add Discussion

Log in to comment