lokinet/llarp/util/logging/file_logger.hpp

55 lines
1.2 KiB
C++
Raw Normal View History

#ifndef LLARP_UTIL_FILE_LOGGER_HPP
#define LLARP_UTIL_FILE_LOGGER_HPP
2019-09-01 12:10:49 +00:00
#include <util/logging/logstream.hpp>
2019-09-01 13:26:16 +00:00
#include <util/thread/thread_pool.hpp>
#include <util/time.hpp>
#include <deque>
namespace llarp
{
/// flushable file based log stream
struct FileLogStream : public ILogStream
{
2019-07-09 13:47:24 +00:00
FileLogStream(std::shared_ptr< thread::ThreadPool > disk, FILE* f,
llarp_time_t flushInterval, bool closefile = true);
2019-07-30 23:42:13 +00:00
~FileLogStream() override;
void
2019-06-13 13:26:34 +00:00
PreLog(std::stringstream& out, LogLevel lvl, const char* fname, int lineno,
const std::string& nodename) const override;
void
Print(LogLevel, const char*, const std::string& msg) override;
void
Tick(llarp_time_t now) override;
void
PostLog(std::stringstream&) const override
{
}
2019-06-13 13:26:34 +00:00
protected:
std::deque< std::string > m_Lines;
private:
bool
ShouldFlush(llarp_time_t now) const;
void
FlushLinesToDisk(llarp_time_t now);
2019-07-09 13:47:24 +00:00
std::shared_ptr< thread::ThreadPool > m_Disk;
2019-06-13 13:26:34 +00:00
FILE* const m_File;
const llarp_time_t m_FlushInterval;
llarp_time_t m_LastFlush = 0;
2019-06-13 13:26:34 +00:00
const bool m_Close;
};
} // namespace llarp
#endif