mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-16 08:55:46 +08:00
33 lines
570 B
C++
33 lines
570 B
C++
#pragma once
|
|
// Flush to file every X writes..
|
|
|
|
namespace c11log
|
|
{
|
|
namespace details
|
|
{
|
|
|
|
class file_flush_helper
|
|
{
|
|
public:
|
|
explicit file_flush_helper(const std::size_t flush_every):
|
|
_flush_every(flush_every),
|
|
_write_counter(0) {};
|
|
|
|
void write(std::ofstream& ofs, const bufpair_t& msg)
|
|
{
|
|
ofs.write(msg.first, msg.second);
|
|
if(++_write_counter == _flush_every)
|
|
{
|
|
ofs.flush();
|
|
_write_counter = 0;
|
|
}
|
|
}
|
|
|
|
private:
|
|
const std::size_t _flush_every;
|
|
std::size_t _write_counter;
|
|
};
|
|
}
|
|
}
|
|
|