|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <cerrno>
|
|
|
|
|
|
|
|
|
|
namespace spdlog
|
|
|
|
|
{
|
|
|
|
@ -58,7 +59,7 @@ public:
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(open_interval));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing");
|
|
|
|
|
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reopen(bool truncate)
|
|
|
|
@ -89,7 +90,7 @@ public:
|
|
|
|
|
size_t msg_size = msg.formatted.size();
|
|
|
|
|
auto data = msg.formatted.data();
|
|
|
|
|
if (std::fwrite(data, 1, msg_size, _fd) != msg_size)
|
|
|
|
|
throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename));
|
|
|
|
|
throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno);
|
|
|
|
|
|
|
|
|
|
if (_force_flush)
|
|
|
|
|
std::fflush(_fd);
|
|
|
|
@ -102,15 +103,15 @@ public:
|
|
|
|
|
|
|
|
|
|
auto pos = ftell(_fd);
|
|
|
|
|
if (fseek(_fd, 0, SEEK_END) != 0)
|
|
|
|
|
throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename));
|
|
|
|
|
throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename), errno);
|
|
|
|
|
|
|
|
|
|
auto file_size = ftell(_fd);
|
|
|
|
|
|
|
|
|
|
if(fseek(_fd, pos, SEEK_SET) !=0)
|
|
|
|
|
throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename));
|
|
|
|
|
throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename), errno);
|
|
|
|
|
|
|
|
|
|
if (file_size == -1)
|
|
|
|
|
throw spdlog_ex("ftell failed on file " + os::filename_to_str(_filename));
|
|
|
|
|
throw spdlog_ex("ftell failed on file " + os::filename_to_str(_filename), errno);
|
|
|
|
|
|
|
|
|
|
return file_size;
|
|
|
|
|
}
|
|
|
|
|