mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-13 17:22:06 +08:00
Update step_file_sink
This commit is contained in:
parent
5c1951acec
commit
eb2118c181
@ -75,7 +75,15 @@ public:
|
|||||||
{
|
{
|
||||||
throw spdlog_ex("step_file_sink: Invalid time step in ctor");
|
throw spdlog_ex("step_file_sink: Invalid time step in ctor");
|
||||||
}
|
}
|
||||||
if (max_size == 0)
|
|
||||||
|
if (!file_header.empty())
|
||||||
|
{
|
||||||
|
pattern_formatter formatter_for_file_header("%v");
|
||||||
|
_file_header.raw << file_header;
|
||||||
|
formatter_for_file_header.format(_file_header);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_size <= _file_header.formatted.size())
|
||||||
{
|
{
|
||||||
throw spdlog_ex("step_file_sink: Invalid max log size in ctor");
|
throw spdlog_ex("step_file_sink: Invalid max log size in ctor");
|
||||||
}
|
}
|
||||||
@ -88,13 +96,6 @@ public:
|
|||||||
throw spdlog_ex("step_file_sink: The temporary extension matches the specified in ctor");
|
throw spdlog_ex("step_file_sink: The temporary extension matches the specified in ctor");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_header.empty())
|
|
||||||
{
|
|
||||||
pattern_formatter formatter_for_file_header("%v");
|
|
||||||
_file_header.raw << file_header;
|
|
||||||
formatter_for_file_header.format(_file_header);
|
|
||||||
}
|
|
||||||
|
|
||||||
_file_helper.open(_current_filename);
|
_file_helper.open(_current_filename);
|
||||||
_current_size = _file_helper.size(); // expensive. called only once
|
_current_size = _file_helper.size(); // expensive. called only once
|
||||||
|
|
||||||
@ -120,14 +121,19 @@ protected:
|
|||||||
|
|
||||||
if (std::chrono::system_clock::now() >= _tp || _current_size + msg_size > _max_size)
|
if (std::chrono::system_clock::now() >= _tp || _current_size + msg_size > _max_size)
|
||||||
{
|
{
|
||||||
close_current_file();
|
filename_t new_filename;
|
||||||
|
std::tie(new_filename, std::ignore) = FileNameCalc::calc_filename(_base_filename, _tmp_ext);
|
||||||
|
if (new_filename != _current_filename)
|
||||||
|
{
|
||||||
|
close_current_file();
|
||||||
|
|
||||||
std::tie(_current_filename, std::ignore) = FileNameCalc::calc_filename(_base_filename, _tmp_ext);
|
// std::tie(_current_filename, std::ignore) = FileNameCalc::calc_filename(_base_filename, _tmp_ext);
|
||||||
_file_helper.open(_current_filename);
|
_file_helper.open(_current_filename);
|
||||||
_tp = _next_tp();
|
_tp = _next_tp();
|
||||||
|
|
||||||
_current_size = _file_header.formatted.size();
|
_current_size = _file_header.formatted.size();
|
||||||
if (_current_size) _file_helper.write(_file_header);
|
if (_current_size) _file_helper.write(_file_header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_size += msg_size;
|
_current_size += msg_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user