pull/502/head
Jeff Becker 5 years ago
parent 9e24557429
commit 40f8434851
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -17,6 +17,7 @@ set(LIB_UTIL_SRC
util/logger.cpp
util/android_logger.cpp
util/ostream_logger.cpp
util/syslog_logger.cpp
util/win32_logger.cpp
util/logic.cpp
util/mem.cpp

@ -67,7 +67,6 @@ namespace llarp
{"metrics", metrics},
{"netdb", netdb},
{"api", api},
{"logging", logging},
{"services", services}};
auto visitor = [&](const char *name, const auto &item) {
@ -76,6 +75,9 @@ namespace llarp
using namespace std::placeholders;
std::for_each(logging.begin(), logging.end(),
std::bind(visitor, "logging", _1));
std::for_each(lokid.begin(), lokid.end(), std::bind(visitor, "lokid", _1));
std::for_each(router.begin(), router.end(),
std::bind(visitor, "router", _1));

@ -14,6 +14,7 @@
#include <util/buffer.hpp>
#include <util/encode.hpp>
#include <util/logger.hpp>
#include <util/logger_syslog.hpp>
#include <util/metrics.hpp>
#include <util/str.hpp>
#include <utp/utp.hpp>
@ -833,6 +834,14 @@ namespace llarp
llarp::LogWarn("failed to load hidden service config for ", key);
}
}
else if(StrEq(section, "logger"))
{
if(StrEq(key, "type") && StrEq(val, "syslog"))
{
LogInfo("Switching to syslog");
LogContext::Instance().logStream = std::make_unique< SysLogStream >();
}
}
else if(StrEq(section, "lokid"))
{
if(StrEq(key, "service-node-seed"))

@ -0,0 +1 @@
#include <util/logger_syslog.hpp>

@ -0,0 +1,21 @@
#ifndef LLARP_UTIL_LOGGER_SYSLOG_HPP
#define LLARP_UTIL_LOGGER_SYSLOG_HPP
#include <util/logstream.hpp>
#include <iostream>
namespace llarp
{
struct SysLogStream : public ILogStream
{
void
PreLog(std::stringstream& s, LogLevel lvl, const char* fname,
int lineno) const override;
void
Print(LogLevel lvl, const char* tag, const std::string& msg) const override;
void
PostLog(std::stringstream& ss) const override;
};
} // namespace llarp
#endif

@ -0,0 +1,60 @@
#ifndef _WIN32
#include <util/logger_syslog.hpp>
#include <util/logger_internal.hpp>
#include <syslog.h>
namespace llarp
{
void
SysLogStream::PreLog(std::stringstream& ss, LogLevel lvl, const char* fname,
int lineno) const
{
switch(lvl)
{
case eLogNone:
break;
case eLogDebug:
ss << "[DBG] ";
break;
case eLogInfo:
ss << "[NFO] ";
break;
case eLogWarn:
ss << "[WRN] ";
break;
case eLogError:
ss << "[ERR] ";
break;
}
ss << "(" << thread_id_string() << ") " << log_timestamp() << " " << fname
<< ":" << lineno << "\t";
}
void
SysLogStream::Print(LogLevel lvl, const char*, const std::string& msg) const
{
switch(lvl)
{
case eLogNone:
return;
case eLogDebug:
::syslog(LOG_DEBUG, "%s", msg.c_str());
return;
case eLogInfo:
::syslog(LOG_INFO, "%s", msg.c_str());
return;
case eLogWarn:
::syslog(LOG_WARNING, "%s", msg.c_str());
return;
case eLogError:
::syslog(LOG_ERR, "%s", msg.c_str());
return;
}
}
void
SysLogStream::PostLog(std::stringstream&) const
{
}
} // namespace llarp
#endif
Loading…
Cancel
Save