Commit eb2118c1 authored by puasonych's avatar puasonych

Update step_file_sink

parent 5c1951ac
......@@ -75,7 +75,15 @@ public:
{
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");
}
......@@ -88,13 +96,6 @@ public:
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);
_current_size = _file_helper.size(); // expensive. called only once
......@@ -119,16 +120,21 @@ protected:
auto msg_size = msg.formatted.size();
if (std::chrono::system_clock::now() >= _tp || _current_size + msg_size > _max_size)
{
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);
_tp = _next_tp();
_current_size = _file_header.formatted.size();
if (_current_size) _file_helper.write(_file_header);
}
}
_current_size += msg_size;
_file_helper.write(msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment