From c92d12bc18127a2e976e2ca780fc44f94e62ae18 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 12 Jan 2023 10:12:30 +0100 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46adb9f0..b0c7fe5e 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ void daily_example() ```c++ // Debug messages can be stored in a ring buffer instead of being logged immediately. // This is useful in order to display debug logs only when really needed (e.g. when error happens). -// When needed, call dump_backtrace() to see them. +// When needed, call dump_backtrace() to dump them to your log. spdlog::enable_backtrace(32); // Store the latest 32 messages in a buffer. Older messages will be dropped. // or my_logger->enable_backtrace(32).. From 05e3a73b162705b37ed464ceb4644addfb03f25b Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 12 Jan 2023 10:15:58 +0100 Subject: [PATCH 2/7] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b0c7fe5e..7cc4db9e 100644 --- a/README.md +++ b/README.md @@ -148,15 +148,14 @@ void daily_example() // This is useful in order to display debug logs only when really needed (e.g. when error happens). // When needed, call dump_backtrace() to dump them to your log. -spdlog::enable_backtrace(32); // Store the latest 32 messages in a buffer. Older messages will be dropped. +spdlog::enable_backtrace(32); // Store the latest 32 messages in a buffer. // or my_logger->enable_backtrace(32).. for(int i = 0; i < 100; i++) { spdlog::debug("Backtrace message {}", i); // not logged yet.. } -// e.g. if some error happened: +// e.g. if some has error happened: spdlog::dump_backtrace(); // log them now! show the last 32 messages - // or my_logger->dump_backtrace(32).. ``` From 5a63426d1cb9d7e16dbe6b6779e041012513202e Mon Sep 17 00:00:00 2001 From: albert-github Date: Sun, 15 Jan 2023 12:41:30 +0100 Subject: [PATCH 3/7] Spelling corrections (#2606) Spelling corrections v1.x --- README.md | 2 +- include/spdlog/details/tcp_client.h | 2 +- include/spdlog/sinks/android_sink.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7cc4db9e..b98a920b 100644 --- a/README.md +++ b/README.md @@ -375,7 +375,7 @@ $ ./example #### Log file open/close event handlers ```c++ // You can get callbacks from spdlog before/after log file has been opened or closed. -// This is useful for cleanup procedures or for adding someting the start/end of the log files. +// This is useful for cleanup procedures or for adding something the start/end of the log files. void file_events_example() { // pass the spdlog::file_event_handlers to file sinks for open/close log file notifications diff --git a/include/spdlog/details/tcp_client.h b/include/spdlog/details/tcp_client.h index 45883f34..e4d7a48e 100644 --- a/include/spdlog/details/tcp_client.h +++ b/include/spdlog/details/tcp_client.h @@ -111,7 +111,7 @@ public: #endif #if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) -# error "tcp_sink would raise SIGPIPE since niether SO_NOSIGPIPE nor MSG_NOSIGNAL are available" +# error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available" #endif } diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index 07dbeea8..8e79638b 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -74,7 +74,7 @@ protected: private: // There might be liblog versions used, that do not support __android_log_buf_write. So we only compile and link against - // __android_log_buf_write, if user explicitely provides a non-default log buffer. Otherwise, when using the default log buffer, always + // __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise, when using the default log buffer, always // log via __android_log_write. template typename std::enable_if(log_id::LOG_ID_MAIN), int>::type android_log(int prio, const char *tag, const char *text) @@ -139,4 +139,4 @@ inline std::shared_ptr android_logger_st(const std::string &logger_name, } // namespace spdlog -#endif // __ANDROID__ \ No newline at end of file +#endif // __ANDROID__ From f29f369a12c701db27e816c6762e914863e8e951 Mon Sep 17 00:00:00 2001 From: espkk Date: Sun, 15 Jan 2023 15:33:40 +0200 Subject: [PATCH 4/7] Add sync to file_helper (#2343) --- include/spdlog/details/file_helper-inl.h | 8 ++++++++ include/spdlog/details/file_helper.h | 1 + include/spdlog/details/os-inl.h | 16 ++++++++++++++-- include/spdlog/details/os.h | 4 ++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/file_helper-inl.h b/include/spdlog/details/file_helper-inl.h index d4528711..3c45d8c0 100644 --- a/include/spdlog/details/file_helper-inl.h +++ b/include/spdlog/details/file_helper-inl.h @@ -90,6 +90,14 @@ SPDLOG_INLINE void file_helper::flush() } } +SPDLOG_INLINE void file_helper::sync() +{ + if(!os::fsync(fd_)) + { + throw_spdlog_ex("Failed to fsync file " + os::filename_to_str(filename_), errno); + } +} + SPDLOG_INLINE void file_helper::close() { if (fd_ != nullptr) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 0f5988b9..f42a5eb1 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -26,6 +26,7 @@ public: void open(const filename_t &fname, bool truncate = false); void reopen(bool truncate); void flush(); + void sync(); void close(); void write(const memory_buf_t &buf); size_t size() const; diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 2ac8cc3f..42acf3fe 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -23,9 +23,10 @@ #ifdef _WIN32 -# include // _get_osfhandle and _isatty support -# include // _get_pid support +# include // for _get_osfhandle, _isatty, _fileno +# include // for _get_pid # include +# include // for FlushFileBuffers # ifdef __MINGW32__ # include @@ -601,6 +602,17 @@ std::string SPDLOG_INLINE getenv(const char *field) #endif } +// Do fsync by FILE descriptor +// Return true on success +SPDLOG_INLINE bool fsync(FILE *fd) +{ +#ifdef _WIN32 + return FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(fd)))) != 0; +#else + return ::fsync(fileno(fd)) == 0; +#endif +} + } // namespace os } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index b154bc47..742482d0 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -109,6 +109,10 @@ SPDLOG_API bool create_dir(const filename_t &path); // return empty string if field not found SPDLOG_API std::string getenv(const char *field); +// Do fsync by FILE descriptor +// Return true on success +SPDLOG_API bool fsync(FILE * fd); + } // namespace os } // namespace details } // namespace spdlog From 435827fe5a4340c192d9e68d7b5cd92205f299a8 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 15 Jan 2023 15:57:08 +0200 Subject: [PATCH 5/7] Update os.h --- include/spdlog/details/os.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 742482d0..b92acb2f 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -109,9 +109,9 @@ SPDLOG_API bool create_dir(const filename_t &path); // return empty string if field not found SPDLOG_API std::string getenv(const char *field); -// Do fsync by FILE descriptor +// Do fsync by FILE object // Return true on success -SPDLOG_API bool fsync(FILE * fd); +SPDLOG_API bool fsync(FILE * f); } // namespace os } // namespace details From 78e86ba01f4ea9f0583eb7efa94ee8a703d73485 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 15 Jan 2023 15:59:41 +0200 Subject: [PATCH 6/7] Update os-inl.h --- include/spdlog/details/os-inl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 42acf3fe..19d4bdc5 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -602,14 +602,14 @@ std::string SPDLOG_INLINE getenv(const char *field) #endif } -// Do fsync by FILE descriptor +// Do fsync by FILE handlerpointer // Return true on success -SPDLOG_INLINE bool fsync(FILE *fd) +SPDLOG_INLINE bool fsync(FILE *fp) { #ifdef _WIN32 - return FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(fd)))) != 0; + return FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(fp)))) != 0; #else - return ::fsync(fileno(fd)) == 0; + return ::fsync(fileno(fp)) == 0; #endif } From 654dbc5c3291a0981e6c473fac199409d41fcde8 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 15 Jan 2023 16:00:26 +0200 Subject: [PATCH 7/7] Update os.h --- include/spdlog/details/os.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index b92acb2f..f55642c1 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -109,9 +109,9 @@ SPDLOG_API bool create_dir(const filename_t &path); // return empty string if field not found SPDLOG_API std::string getenv(const char *field); -// Do fsync by FILE object -// Return true on success -SPDLOG_API bool fsync(FILE * f); +// Do fsync by FILE objectpointer. +// Return true on success. +SPDLOG_API bool fsync(FILE * fp); } // namespace os } // namespace details