add file event handlers
This commit is contained in:
@@ -20,6 +20,10 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE file_helper::file_helper(const file_event_handlers_t& event_handlers)
|
||||
: event_handlers_(event_handlers)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE file_helper::~file_helper()
|
||||
{
|
||||
close();
|
||||
@@ -52,6 +56,10 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
||||
}
|
||||
if (!os::fopen_s(&fd_, fname, mode))
|
||||
{
|
||||
if (event_handlers_.after_open)
|
||||
{
|
||||
event_handlers_.after_open(filename_, fd_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,8 +87,18 @@ SPDLOG_INLINE void file_helper::close()
|
||||
{
|
||||
if (fd_ != nullptr)
|
||||
{
|
||||
if (event_handlers_.before_close)
|
||||
{
|
||||
event_handlers_.before_close(filename_, fd_);
|
||||
}
|
||||
|
||||
std::fclose(fd_);
|
||||
fd_ = nullptr;
|
||||
|
||||
if (event_handlers_.after_close)
|
||||
{
|
||||
event_handlers_.after_close(filename_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user