mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
6 years ago
|
#ifndef LLARP_UTIL_LOG_STREAM_HPP
|
||
|
#define LLARP_UTIL_LOG_STREAM_HPP
|
||
5 years ago
|
#include <util/logging/loglevel.hpp>
|
||
|
|
||
|
#include <util/time.hpp>
|
||
|
|
||
6 years ago
|
#include <memory>
|
||
|
#include <string>
|
||
|
#include <sstream>
|
||
6 years ago
|
|
||
6 years ago
|
namespace llarp
|
||
|
{
|
||
|
/// logger stream interface
|
||
|
struct ILogStream
|
||
|
{
|
||
5 years ago
|
virtual ~ILogStream() = default;
|
||
6 years ago
|
|
||
|
virtual void
|
||
5 years ago
|
PreLog(std::stringstream& out, LogLevel lvl, const char* fname, int lineno,
|
||
|
const std::string& nodename) const = 0;
|
||
|
|
||
6 years ago
|
virtual void
|
||
6 years ago
|
Print(LogLevel lvl, const char* filename, const std::string& msg) = 0;
|
||
6 years ago
|
|
||
|
virtual void
|
||
|
PostLog(std::stringstream& out) const = 0;
|
||
6 years ago
|
|
||
5 years ago
|
virtual void
|
||
|
AppendLog(LogLevel lvl, const char* fname, int lineno,
|
||
|
const std::string& nodename, const std::string msg)
|
||
|
{
|
||
|
std::stringstream ss;
|
||
|
PreLog(ss, lvl, fname, lineno, nodename);
|
||
|
ss << msg;
|
||
|
PostLog(ss);
|
||
|
Print(lvl, fname, ss.str());
|
||
|
}
|
||
|
|
||
6 years ago
|
/// called every end of event loop tick
|
||
|
virtual void
|
||
|
Tick(llarp_time_t now) = 0;
|
||
6 years ago
|
};
|
||
|
|
||
|
using ILogStream_ptr = std::unique_ptr< ILogStream >;
|
||
|
|
||
|
} // namespace llarp
|
||
|
#endif
|