Commit 2400cf16 authored by gabime's avatar gabime

Merge branch 'issue-#1483' into v1.x

parents bbe3ace5 3b87eb3d
...@@ -32,7 +32,7 @@ SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg) ...@@ -32,7 +32,7 @@ SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
} }
else else
{ {
SPDLOG_THROW(spdlog_ex("async log: thread pool doesn't exist anymore")); throw_spdlog_ex("async log: thread pool doesn't exist anymore");
} }
} }
...@@ -45,7 +45,7 @@ SPDLOG_INLINE void spdlog::async_logger::flush_() ...@@ -45,7 +45,7 @@ SPDLOG_INLINE void spdlog::async_logger::flush_()
} }
else else
{ {
SPDLOG_THROW(spdlog_ex("async flush: thread pool doesn't exist anymore")); throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
} }
} }
......
...@@ -63,4 +63,14 @@ SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT ...@@ -63,4 +63,14 @@ SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT
return msg_.c_str(); return msg_.c_str();
} }
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
{
SPDLOG_THROW( spdlog_ex(msg, last_errno));
}
SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
{
SPDLOG_THROW( spdlog_ex(std::move(msg)));
}
} // namespace spdlog } // namespace spdlog
...@@ -204,6 +204,9 @@ private: ...@@ -204,6 +204,9 @@ private:
std::string msg_; std::string msg_;
}; };
void throw_spdlog_ex(const std::string &msg, int last_errno);
void throw_spdlog_ex(std::string msg);
struct source_loc struct source_loc
{ {
SPDLOG_CONSTEXPR source_loc() = default; SPDLOG_CONSTEXPR source_loc() = default;
...@@ -236,7 +239,6 @@ std::unique_ptr<T> make_unique(Args &&... args) ...@@ -236,7 +239,6 @@ std::unique_ptr<T> make_unique(Args &&... args)
} }
#endif #endif
} // namespace details } // namespace details
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
......
...@@ -43,14 +43,14 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) ...@@ -43,14 +43,14 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
details::os::sleep_for_millis(open_interval_); details::os::sleep_for_millis(open_interval_);
} }
SPDLOG_THROW(spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno)); throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno);
} }
SPDLOG_INLINE void file_helper::reopen(bool truncate) SPDLOG_INLINE void file_helper::reopen(bool truncate)
{ {
if (filename_.empty()) if (filename_.empty())
{ {
SPDLOG_THROW(spdlog_ex("Failed re opening file - was not opened before")); throw_spdlog_ex("Failed re opening file - was not opened before");
} }
this->open(filename_, truncate); this->open(filename_, truncate);
} }
...@@ -75,7 +75,7 @@ SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) ...@@ -75,7 +75,7 @@ SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf)
auto data = buf.data(); auto data = buf.data();
if (std::fwrite(data, 1, msg_size, fd_) != msg_size) if (std::fwrite(data, 1, msg_size, fd_) != msg_size)
{ {
SPDLOG_THROW(spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno)); throw_spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno);
} }
} }
...@@ -83,7 +83,7 @@ SPDLOG_INLINE size_t file_helper::size() const ...@@ -83,7 +83,7 @@ SPDLOG_INLINE size_t file_helper::size() const
{ {
if (fd_ == nullptr) if (fd_ == nullptr)
{ {
SPDLOG_THROW(spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(filename_))); throw_spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(filename_));
} }
return os::filesize(fd_); return os::filesize(fd_);
} }
......
...@@ -204,7 +204,7 @@ SPDLOG_INLINE size_t filesize(FILE *f) ...@@ -204,7 +204,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
{ {
if (f == nullptr) if (f == nullptr)
{ {
SPDLOG_THROW(spdlog_ex("Failed getting file size. fd is null")); throw_spdlog_ex("Failed getting file size. fd is null");
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int fd = ::_fileno(f); int fd = ::_fileno(f);
...@@ -245,7 +245,8 @@ SPDLOG_INLINE size_t filesize(FILE *f) ...@@ -245,7 +245,8 @@ SPDLOG_INLINE size_t filesize(FILE *f)
} }
#endif #endif
#endif #endif
SPDLOG_THROW(spdlog_ex("Failed getting file size from fd", errno)); throw_spdlog_ex("Failed getting file size from fd", errno);
return 0; // will not be reached.
} }
// Return utc offset in minutes or throw spdlog_ex on failure // Return utc offset in minutes or throw spdlog_ex on failure
......
...@@ -284,7 +284,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) ...@@ -284,7 +284,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
{ {
if (loggers_.find(logger_name) != loggers_.end()) if (loggers_.find(logger_name) != loggers_.end())
{ {
SPDLOG_THROW(spdlog_ex("logger with name '" + logger_name + "' already exists")); throw_spdlog_ex("logger with name '" + logger_name + "' already exists");
} }
} }
......
...@@ -55,7 +55,7 @@ class tcp_client ...@@ -55,7 +55,7 @@ class tcp_client
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error, ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL); MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
SPDLOG_THROW(spdlog_ex(fmt::format("tcp_sink - {}: {}", msg, buf))); throw_spdlog_ex(fmt::format("tcp_sink - {}: {}", msg, buf));
} }
public: public:
......
...@@ -18,8 +18,8 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std ...@@ -18,8 +18,8 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std
{ {
if (threads_n == 0 || threads_n > 1000) if (threads_n == 0 || threads_n > 1000)
{ {
SPDLOG_THROW(spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid " throw_spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
"range is 1-1000)")); "range is 1-1000)");
} }
for (size_t i = 0; i < threads_n; i++) for (size_t i = 0; i < threads_n; i++)
{ {
......
...@@ -64,7 +64,7 @@ protected: ...@@ -64,7 +64,7 @@ protected:
if (ret < 0) if (ret < 0)
{ {
SPDLOG_THROW(spdlog_ex("__android_log_write() failed", ret)); throw_spdlog_ex("__android_log_write() failed", ret);
} }
} }
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
{ {
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
{ {
SPDLOG_THROW(spdlog_ex("daily_file_sink: Invalid rotation time in ctor")); throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
} }
auto now = log_clock::now(); auto now = log_clock::now();
...@@ -164,7 +164,7 @@ private: ...@@ -164,7 +164,7 @@ private:
if (!ok) if (!ok)
{ {
filenames_q_.push_back(std::move(current_file)); filenames_q_.push_back(std::move(current_file));
SPDLOG_THROW(spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), errno)); throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), errno);
} }
} }
filenames_q_.push_back(std::move(current_file)); filenames_q_.push_back(std::move(current_file));
......
...@@ -72,7 +72,7 @@ protected: ...@@ -72,7 +72,7 @@ protected:
if (err) if (err)
{ {
SPDLOG_THROW(spdlog_ex("Failed writing to systemd", errno)); throw_spdlog_ex("Failed writing to systemd", errno);
} }
} }
......
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
{ {
if (!::IsValidSid(psid)) if (!::IsValidSid(psid))
{ {
SPDLOG_THROW(spdlog_ex("sid_t::sid_t(): invalid SID received")); throw_spdlog_ex("sid_t::sid_t(): invalid SID received");
} }
auto const sid_length{::GetLengthSid(psid)}; auto const sid_length{::GetLengthSid(psid)};
......
...@@ -158,7 +158,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_ ...@@ -158,7 +158,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_
bool ok = ::WriteFile(out_handle_, formatted.data() + total_written, size - total_written, &bytes_written, nullptr) != 0; bool ok = ::WriteFile(out_handle_, formatted.data() + total_written, size - total_written, &bytes_written, nullptr) != 0;
if (!ok || bytes_written == 0) if (!ok || bytes_written == 0)
{ {
SPDLOG_THROW(spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError()))); throw_spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError()));
} }
total_written += bytes_written; total_written += bytes_written;
} while (total_written < size); } while (total_written < size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment