mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-16 00:45:48 +08:00
33 lines
591 B
C++
33 lines
591 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),
|
|
_flush_countdown(flush_every) {};
|
|
|
|
void write(const std::string& msg, std::ofstream& ofs)
|
|
{
|
|
ofs.write(msg.data(), msg.size());
|
|
if(--_flush_countdown == 0)
|
|
{
|
|
ofs.flush();
|
|
_flush_countdown = _flush_every;
|
|
}
|
|
}
|
|
|
|
private:
|
|
const std::size_t _flush_every;
|
|
std::size_t _flush_countdown;
|
|
};
|
|
}
|
|
}
|
|
|