mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 17:41:34 +08:00
Fixed rotating_logger_mt does not rotate properly if app restarts #116
This commit is contained in:
parent
f8b728ea8a
commit
ea1a92769b
@ -113,6 +113,29 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long size()
|
||||||
|
{
|
||||||
|
if (!_fd)
|
||||||
|
throw spdlog_ex("Cannot use size() on closed file " + _filename);
|
||||||
|
|
||||||
|
auto pos = ftell(_fd);
|
||||||
|
if (fseek(_fd, 0, SEEK_END) != 0)
|
||||||
|
throw spdlog_ex("fseek failed on file " + _filename);
|
||||||
|
|
||||||
|
auto size = ftell(_fd);
|
||||||
|
|
||||||
|
if(fseek(_fd, pos, SEEK_SET) !=0)
|
||||||
|
throw spdlog_ex("fseek failed on file " + _filename);
|
||||||
|
|
||||||
|
if (size == -1)
|
||||||
|
throw spdlog_ex("ftell failed on file " + _filename);
|
||||||
|
|
||||||
|
|
||||||
|
return size;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& filename() const
|
const std::string& filename() const
|
||||||
{
|
{
|
||||||
return _filename;
|
return _filename;
|
||||||
@ -132,6 +155,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE* _fd;
|
FILE* _fd;
|
||||||
std::string _filename;
|
std::string _filename;
|
||||||
|
@ -82,6 +82,7 @@ public:
|
|||||||
_file_helper(force_flush)
|
_file_helper(force_flush)
|
||||||
{
|
{
|
||||||
_file_helper.open(calc_filename(_base_filename, 0, _extension));
|
_file_helper.open(calc_filename(_base_filename, 0, _extension));
|
||||||
|
_current_size = _file_helper.size(); //expensive. called only once
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush() override
|
void flush() override
|
||||||
|
Loading…
Reference in New Issue
Block a user