mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
5c457ff486
* use std::source_location instead of godawful macros in logging * remove unused/absolutely haram af json logstream * fix bug in android logger where it doesn't respect eLogNone
66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include "ostream_logger.hpp"
|
|
#include "logger_internal.hpp"
|
|
|
|
namespace llarp
|
|
{
|
|
OStreamLogStream::OStreamLogStream(bool withColours, std::ostream& out)
|
|
: m_withColours(withColours), m_Out(out)
|
|
{}
|
|
|
|
void
|
|
OStreamLogStream::PreLog(
|
|
std::stringstream& ss,
|
|
LogLevel lvl,
|
|
std::string_view filename,
|
|
int lineno,
|
|
const std::string& nodename) const
|
|
{
|
|
if (m_withColours)
|
|
{
|
|
switch (lvl)
|
|
{
|
|
case eLogNone:
|
|
return;
|
|
case eLogTrace:
|
|
case eLogDebug:
|
|
ss << (char)27 << "[0m";
|
|
break;
|
|
case eLogInfo:
|
|
ss << (char)27 << "[1m";
|
|
break;
|
|
case eLogWarn:
|
|
ss << (char)27 << "[1;33m";
|
|
break;
|
|
case eLogError:
|
|
ss << (char)27 << "[1;31m";
|
|
break;
|
|
}
|
|
}
|
|
ss << "[" << LogLevelToString(lvl) << "] ";
|
|
ss << "[" << nodename << "]"
|
|
<< "(" << thread_id_string() << ") " << log_timestamp() << " " << filename << ":" << lineno
|
|
<< "\t";
|
|
}
|
|
|
|
void
|
|
OStreamLogStream::PostLog(std::stringstream& ss) const
|
|
{
|
|
if (m_withColours)
|
|
ss << (char)27 << "[0;0m";
|
|
ss << std::endl;
|
|
}
|
|
|
|
void
|
|
OStreamLogStream::Print(LogLevel, std::string_view, const std::string& msg)
|
|
{
|
|
m_Out << msg << std::flush;
|
|
}
|
|
|
|
void
|
|
OStreamLogStream::ImmediateFlush()
|
|
{
|
|
m_Out << std::flush;
|
|
}
|
|
|
|
} // namespace llarp
|