Skip to content

Commit

Permalink
Merge pull request #2048 from D-r-P-3-p-p-3-r/feature/2046_improved_e…
Browse files Browse the repository at this point in the history
…rror_handler_message

Added additional information for error handler
  • Loading branch information
gabime authored Aug 17, 2021
2 parents c2550ac + 0d10e21 commit deb178a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/spdlog/async_logger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg
{
sink->log(msg);
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(msg.source)
}
}

Expand All @@ -80,7 +80,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
{
sink->flush();
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(source_loc())
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/spdlog/logger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg)
{
sink->log(msg);
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(msg.source)
}
}

Expand All @@ -203,7 +203,7 @@ SPDLOG_INLINE void logger::flush_()
{
sink->flush();
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(source_loc())
}
}

Expand Down
19 changes: 13 additions & 6 deletions include/spdlog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@
#include <vector>

#ifndef SPDLOG_NO_EXCEPTIONS
# define SPDLOG_LOGGER_CATCH() \
# define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) \
{ \
err_handler_(ex.what()); \
if(location.filename) \
{ \
err_handler_(fmt::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
} \
else \
{ \
err_handler_(ex.what()); \
} \
} \
catch (...) \
{ \
err_handler_("Rethrowing unknown exception in logger"); \
throw; \
}
#else
# define SPDLOG_LOGGER_CATCH()
# define SPDLOG_LOGGER_CATCH(additional_info)
#endif

namespace spdlog {
Expand Down Expand Up @@ -333,7 +340,7 @@ class SPDLOG_API logger
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(loc)
}

#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
Expand All @@ -356,7 +363,7 @@ class SPDLOG_API logger
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(loc)
}

// T can be statically converted to wstring_view, and no formatting needed.
Expand All @@ -376,7 +383,7 @@ class SPDLOG_API logger
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}
SPDLOG_LOGGER_CATCH()
SPDLOG_LOGGER_CATCH(loc)
}

#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
Expand Down

0 comments on commit deb178a

Please sign in to comment.