Switch additional information to source location of bad log message

This commit is contained in:
Wolfgang Petroschka 2021-08-17 15:26:59 +02:00
parent df45d78d14
commit ed27592537
3 changed files with 23 additions and 13 deletions

View File

@ -62,7 +62,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg
{
sink->log(msg);
}
SPDLOG_LOGGER_CATCH(msg.payload)
SPDLOG_LOGGER_CATCH(msg.source)
}
}
@ -80,7 +80,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
{
sink->flush();
}
SPDLOG_LOGGER_CATCH("")
SPDLOG_LOGGER_CATCH(source_loc())
}
}

View File

@ -185,7 +185,7 @@ SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg)
{
sink->log(msg);
}
SPDLOG_LOGGER_CATCH(msg.payload)
SPDLOG_LOGGER_CATCH(msg.source)
}
}
@ -203,7 +203,7 @@ SPDLOG_INLINE void logger::flush_()
{
sink->flush();
}
SPDLOG_LOGGER_CATCH("")
SPDLOG_LOGGER_CATCH(source_loc())
}
}

View File

@ -28,10 +28,24 @@
#include <vector>
#ifndef SPDLOG_NO_EXCEPTIONS
# define SPDLOG_LOGGER_CATCH(additional_info) \
# define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) \
{ \
err_handler_(fmt::format("{} ({})", ex.what(), additional_info)); \
if(location.filename) \
{ \
try \
{ \
err_handler_(fmt::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
} \
catch (const std::exception &ex) \
{ \
err_handler_(ex.what()); \
} \
} \
else \
{ \
err_handler_(ex.what()); \
} \
} \
catch (...) \
{ \
@ -333,7 +347,7 @@ protected:
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(fmt)
SPDLOG_LOGGER_CATCH(loc)
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
@ -356,9 +370,7 @@ protected:
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}
// TODO: This isn't working yet.
SPDLOG_LOGGER_CATCH("")
//SPDLOG_LOGGER_CATCH(fmt)
SPDLOG_LOGGER_CATCH(loc)
}
// T can be statically converted to wstring_view, and no formatting needed.
@ -378,9 +390,7 @@ protected:
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}
// TODO: This isn't working yet.
SPDLOG_LOGGER_CATCH("")
//SPDLOG_LOGGER_CATCH(msg)
SPDLOG_LOGGER_CATCH(loc)
}
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT