mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
Print error and abort instead of throw if SPDLOG_NO_EXEPTIONS is defined
This commit is contained in:
@@ -39,14 +39,14 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
||||
details::os::sleep_for_millis(open_interval);
|
||||
}
|
||||
|
||||
SPDLOG_THROW spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
|
||||
SPDLOG_THROW(spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::reopen(bool truncate)
|
||||
{
|
||||
if (_filename.empty())
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("Failed re opening file - was not opened before");
|
||||
SPDLOG_THROW(spdlog_ex("Failed re opening file - was not opened before"));
|
||||
}
|
||||
open(_filename, truncate);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf)
|
||||
auto data = buf.data();
|
||||
if (std::fwrite(data, 1, msg_size, fd_) != msg_size)
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno);
|
||||
SPDLOG_THROW(spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ SPDLOG_INLINE size_t file_helper::size() const
|
||||
{
|
||||
if (fd_ == nullptr)
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
|
||||
SPDLOG_THROW(spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename)));
|
||||
}
|
||||
return os::filesize(fd_);
|
||||
}
|
||||
|
@@ -126,7 +126,7 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f)
|
||||
auto fd = fileno(f);
|
||||
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("fcntl with FD_CLOEXEC failed", errno);
|
||||
SPDLOG_THROW(spdlog_ex("fcntl with FD_CLOEXEC failed", errno));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -192,7 +192,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
|
||||
{
|
||||
if (f == nullptr)
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("Failed getting file size. fd is null");
|
||||
SPDLOG_THROW(spdlog_ex("Failed getting file size. fd is null"));
|
||||
}
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
int fd = _fileno(f);
|
||||
@@ -229,7 +229,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
SPDLOG_THROW spdlog_ex("Failed getting file size from fd", errno);
|
||||
SPDLOG_THROW(spdlog_ex("Failed getting file size from fd", errno));
|
||||
}
|
||||
|
||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||
@@ -245,7 +245,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
|
||||
auto rv = GetDynamicTimeZoneInformation(&tzinfo);
|
||||
#endif
|
||||
if (rv == TIME_ZONE_ID_INVALID)
|
||||
throw spdlog::spdlog_ex("Failed getting timezone info. ", errno);
|
||||
SPDLOG_THROW(spdlog::spdlog_ex("Failed getting timezone info. ", errno));
|
||||
|
||||
int offset = -tzinfo.Bias;
|
||||
if (tm.tm_isdst)
|
||||
@@ -408,7 +408,7 @@ SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memor
|
||||
{
|
||||
if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
|
||||
{
|
||||
throw spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8");
|
||||
SPDLOG_THROW(spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8"));
|
||||
}
|
||||
|
||||
int wstr_size = static_cast<int>(wstr.size());
|
||||
@@ -436,7 +436,7 @@ SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memor
|
||||
}
|
||||
}
|
||||
|
||||
throw spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
SPDLOG_THROW(spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())));
|
||||
}
|
||||
#endif // (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
|
||||
|
||||
|
@@ -245,7 +245,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
|
||||
{
|
||||
if (loggers_.find(logger_name) != loggers_.end())
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("logger with name '" + logger_name + "' already exists");
|
||||
SPDLOG_THROW(spdlog_ex("logger with name '" + logger_name + "' already exists"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,8 +17,8 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std
|
||||
{
|
||||
if (threads_n == 0 || threads_n > 1000)
|
||||
{
|
||||
SPDLOG_THROW spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)");
|
||||
SPDLOG_THROW(spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)"));
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++)
|
||||
{
|
||||
@@ -36,7 +36,7 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
// message all threads to terminate gracefully join them
|
||||
SPDLOG_INLINE thread_pool::~thread_pool()
|
||||
{
|
||||
try
|
||||
SPDLOG_TRY
|
||||
{
|
||||
for (size_t i = 0; i < threads_.size(); i++)
|
||||
{
|
||||
@@ -48,8 +48,7 @@ SPDLOG_INLINE thread_pool::~thread_pool()
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{}
|
||||
SPDLOG_CATCH_ALL() {}
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, details::log_msg &msg, async_overflow_policy overflow_policy)
|
||||
|
@@ -31,20 +31,20 @@ enum class async_msg_type
|
||||
// Movable only. should never be copied
|
||||
struct async_msg
|
||||
{
|
||||
async_msg_type msg_type;
|
||||
level::level_enum level;
|
||||
async_msg_type msg_type;
|
||||
level::level_enum level;
|
||||
log_clock::time_point time;
|
||||
size_t thread_id;
|
||||
size_t thread_id;
|
||||
fmt::basic_memory_buffer<char, 176> raw;
|
||||
|
||||
source_loc source;
|
||||
async_logger_ptr worker_ptr;
|
||||
|
||||
async_msg()
|
||||
:msg_type(async_msg_type::log),
|
||||
level(level::info),
|
||||
thread_id(0)
|
||||
{}
|
||||
async_msg()
|
||||
: msg_type(async_msg_type::log)
|
||||
, level(level::info)
|
||||
, thread_id(0)
|
||||
{}
|
||||
~async_msg() = default;
|
||||
|
||||
// should only be moved in or out of the queue..
|
||||
@@ -52,17 +52,18 @@ struct async_msg
|
||||
|
||||
// support for vs2013 move
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
||||
async_msg(async_msg &&other) : msg_type(other.msg_type),
|
||||
level(other.level),
|
||||
time(other.time),
|
||||
thread_id(other.thread_id),
|
||||
raw(move(other.raw)),
|
||||
msg_id(other.msg_id),
|
||||
source(other.source),
|
||||
worker_ptr(std::move(other.worker_ptr))
|
||||
async_msg(async_msg &&other)
|
||||
: msg_type(other.msg_type)
|
||||
, level(other.level)
|
||||
, time(other.time)
|
||||
, thread_id(other.thread_id)
|
||||
, raw(move(other.raw))
|
||||
, msg_id(other.msg_id)
|
||||
, source(other.source)
|
||||
, worker_ptr(std::move(other.worker_ptr))
|
||||
{}
|
||||
|
||||
async_msg &operator=(async_msg &&other)
|
||||
async_msg &operator=(async_msg &&other)
|
||||
{
|
||||
msg_type = other.msg_type;
|
||||
level = other.level;
|
||||
|
Reference in New Issue
Block a user