mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
Switch additional information to source location of bad log message
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user