lokinet/llarp/util/ostream_logger.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2019-04-11 12:58:23 +00:00
#include <util/ostream_logger.hpp>
#include <util/logger_internal.hpp>
namespace llarp
{
OStreamLogStream::OStreamLogStream(std::ostream& out) : m_Out(out)
{
}
void
OStreamLogStream::PreLog(std::stringstream& ss, LogLevel lvl,
2019-06-13 13:26:34 +00:00
const char* fname, int lineno,
const std::string& nodename) const
2019-04-11 12:58:23 +00:00
{
switch(lvl)
{
case eLogNone:
break;
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;
}
2019-06-13 13:26:34 +00:00
ss << "[" << LogLevelToString(lvl) << "] ";
ss << "[" << nodename << "]"
<< "(" << thread_id_string() << ") " << log_timestamp() << " " << fname
2019-04-11 12:58:23 +00:00
<< ":" << lineno << "\t";
}
void
OStreamLogStream::PostLog(std::stringstream& ss) const
{
ss << (char)27 << "[0;0m" << std::endl;
}
void
OStreamLogStream::Print(LogLevel, const char*, const std::string& msg)
2019-04-11 12:58:23 +00:00
{
m_Out << msg << std::flush;
2019-04-11 12:58:23 +00:00
}
} // namespace llarp