mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-13 17:22:06 +08:00
simplfiy a little the use of fmt:safe_strerror
This commit is contained in:
parent
d78ddcee24
commit
faea32c9f9
@ -153,15 +153,18 @@ public:
|
|||||||
|
|
||||||
spdlog_ex(const std::string &msg, int last_errno)
|
spdlog_ex(const std::string &msg, int last_errno)
|
||||||
{
|
{
|
||||||
|
std::string errno_string;
|
||||||
char buf[256], *buf_ptr = buf;
|
char buf[256], *buf_ptr = buf;
|
||||||
SPDLOG_CONSTEXPR auto buf_size = sizeof(buf);
|
|
||||||
if (fmt::safe_strerror(last_errno, buf_ptr, buf_size) != 0)
|
if (fmt::safe_strerror(last_errno, buf_ptr, sizeof(buf)) == 0)
|
||||||
{
|
{
|
||||||
buf_ptr = buf;
|
errno_string = buf_ptr;
|
||||||
char unknown[] = "Unknown error";
|
|
||||||
std::copy(unknown, unknown + sizeof(unknown), buf_ptr);
|
|
||||||
}
|
}
|
||||||
_msg = msg + ": " + std::string(buf_ptr);
|
else
|
||||||
|
{
|
||||||
|
errno_string = "Unknown error";
|
||||||
|
}
|
||||||
|
_msg = msg + ": " + errno_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *what() const SPDLOG_NOEXCEPT override
|
const char *what() const SPDLOG_NOEXCEPT override
|
||||||
@ -182,6 +185,13 @@ using filename_t = std::wstring;
|
|||||||
using filename_t = std::string;
|
using filename_t = std::string;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SPDLOG_CATCH_AND_HANDLE catch (const std::exception &ex) {_err_handler(ex.what());}\
|
#define SPDLOG_CATCH_AND_HANDLE \
|
||||||
catch (...) {_err_handler("Unknown exeption in logger");}
|
catch (const std::exception &ex) \
|
||||||
|
{ \
|
||||||
|
_err_handler(ex.what()); \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
_err_handler("Unknown exeption in logger"); \
|
||||||
|
}
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue
Block a user