Merge branch 'v1.x' into attributes

pull/2595/head
Bailey Chittle 3 years ago
commit 6097b84f85

@ -146,17 +146,16 @@ 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.
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)..
```
@ -376,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

@ -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)

@ -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;

@ -23,9 +23,10 @@
#ifdef _WIN32
# include <io.h> // _get_osfhandle and _isatty support
# include <process.h> // _get_pid support
# include <io.h> // for _get_osfhandle, _isatty, _fileno
# include <process.h> // for _get_pid
# include <spdlog/details/windows_include.h>
# include <fileapi.h> // for FlushFileBuffers
# ifdef __MINGW32__
# include <share.h>
@ -601,6 +602,17 @@ std::string SPDLOG_INLINE getenv(const char *field)
#endif
}
// Do fsync by FILE handlerpointer
// Return true on success
SPDLOG_INLINE bool fsync(FILE *fp)
{
#ifdef _WIN32
return FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp)))) != 0;
#else
return ::fsync(fileno(fp)) == 0;
#endif
}
} // namespace os
} // namespace details
} // namespace spdlog

@ -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 objectpointer.
// Return true on success.
SPDLOG_API bool fsync(FILE * fp);
} // namespace os
} // namespace details
} // namespace spdlog

@ -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
}

@ -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<int ID = BufferID>
typename std::enable_if<ID == static_cast<int>(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<logger> android_logger_st(const std::string &logger_name,
} // namespace spdlog
#endif // __ANDROID__
#endif // __ANDROID__

Loading…
Cancel
Save