lokinet/llarp/util/logging/logstream.hpp

60 lines
1.2 KiB
C++
Raw Normal View History

2019-04-11 12:58:23 +00:00
#ifndef LLARP_UTIL_LOG_STREAM_HPP
#define LLARP_UTIL_LOG_STREAM_HPP
2019-09-01 12:10:49 +00:00
#include <util/logging/loglevel.hpp>
#include <util/time.hpp>
2019-04-11 12:58:23 +00:00
#include <memory>
#include <string>
#include <sstream>
2019-04-11 12:58:23 +00:00
namespace llarp
{
/// logger stream interface
struct ILogStream
{
2019-07-24 14:17:54 +00:00
virtual ~ILogStream() = default;
2019-04-11 12:58:23 +00:00
virtual void
PreLog(
std::stringstream& out,
LogLevel lvl,
const char* fname,
int lineno,
const std::string& nodename) const = 0;
2019-06-13 13:26:34 +00:00
2019-04-11 12:58:23 +00:00
virtual void
Print(LogLevel lvl, const char* filename, const std::string& msg) = 0;
2019-04-11 12:58:23 +00:00
virtual void
PostLog(std::stringstream& out) const = 0;
2019-06-13 13:26:34 +00:00
virtual void
AppendLog(
LogLevel lvl,
const char* fname,
int lineno,
const std::string& nodename,
const std::string msg)
2019-06-13 13:26:34 +00:00
{
std::stringstream ss;
PreLog(ss, lvl, fname, lineno, nodename);
ss << msg;
PostLog(ss);
Print(lvl, fname, ss.str());
}
/// A blocking call to flush to disk. Should only be called in rare circumstances.
virtual void
ImmediateFlush() = 0;
/// called every end of event loop tick
virtual void
Tick(llarp_time_t now) = 0;
2019-04-11 12:58:23 +00:00
};
using ILogStream_ptr = std::unique_ptr<ILogStream>;
2019-04-11 12:58:23 +00:00
} // namespace llarp
#endif