2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
|
|
|
#include "loglevel.hpp"
|
2019-09-01 12:10:49 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/time.hpp>
|
2019-09-01 12:10:49 +00:00
|
|
|
|
2019-04-11 12:58:23 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2021-05-11 11:22:36 +00:00
|
|
|
#include <string_view>
|
2019-04-16 13:20:48 +00:00
|
|
|
|
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
|
2020-04-07 18:38:56 +00:00
|
|
|
PreLog(
|
|
|
|
std::stringstream& out,
|
|
|
|
LogLevel lvl,
|
2021-05-11 11:22:36 +00:00
|
|
|
std::string_view filename,
|
2020-04-07 18:38:56 +00:00
|
|
|
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
|
2021-05-11 11:22:36 +00:00
|
|
|
Print(LogLevel lvl, std::string_view filename, const std::string& msg) = 0;
|
2019-04-11 12:58:23 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
PostLog(std::stringstream& out) const = 0;
|
2019-04-16 13:20:48 +00:00
|
|
|
|
2019-06-13 13:26:34 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
AppendLog(
|
|
|
|
LogLevel lvl,
|
2021-05-11 11:22:36 +00:00
|
|
|
std::string_view filename,
|
2020-04-07 18:38:56 +00:00
|
|
|
int lineno,
|
|
|
|
const std::string& nodename,
|
|
|
|
const std::string msg)
|
2019-06-13 13:26:34 +00:00
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2021-05-11 11:22:36 +00:00
|
|
|
PreLog(ss, lvl, filename, lineno, nodename);
|
2019-06-13 13:26:34 +00:00
|
|
|
ss << msg;
|
|
|
|
PostLog(ss);
|
2021-05-11 11:22:36 +00:00
|
|
|
Print(lvl, filename, ss.str());
|
2019-06-13 13:26:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 16:47:56 +00:00
|
|
|
/// A blocking call to flush to disk. Should only be called in rare circumstances.
|
|
|
|
virtual void
|
|
|
|
ImmediateFlush() = 0;
|
|
|
|
|
2019-04-16 13:20:48 +00:00
|
|
|
/// called every end of event loop tick
|
|
|
|
virtual void
|
|
|
|
Tick(llarp_time_t now) = 0;
|
2019-04-11 12:58:23 +00:00
|
|
|
};
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using ILogStream_ptr = std::unique_ptr<ILogStream>;
|
2019-04-11 12:58:23 +00:00
|
|
|
|
|
|
|
} // namespace llarp
|