2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/logger.hpp>
|
|
|
|
#include <util/logging/logger.h>
|
|
|
|
#include <util/logging/ostream_logger.hpp>
|
2019-04-11 12:58:23 +00:00
|
|
|
#if defined(_WIN32)
|
2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/win32_logger.hpp>
|
2019-04-11 12:58:23 +00:00
|
|
|
#endif
|
|
|
|
#if defined(ANDROID)
|
2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/android_logger.hpp>
|
2019-04-11 12:58:23 +00:00
|
|
|
#endif
|
2018-05-27 13:42:55 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-04-11 12:58:23 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
using Stream_t = Win32LogStream;
|
|
|
|
#define _LOGSTREAM_INIT std::cout
|
|
|
|
#else
|
|
|
|
#if defined(ANDROID)
|
|
|
|
using Stream_t = AndroidLogStream;
|
|
|
|
#define _LOGSTREAM_INIT
|
|
|
|
#else
|
|
|
|
using Stream_t = OStreamLogStream;
|
|
|
|
#define _LOGSTREAM_INIT std::cout
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LogContext::LogContext()
|
|
|
|
: logStream(std::make_unique< Stream_t >(_LOGSTREAM_INIT))
|
2019-06-10 13:20:48 +00:00
|
|
|
, started(llarp::time_now_ms())
|
2019-04-11 12:58:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LogContext&
|
|
|
|
LogContext::Instance()
|
|
|
|
{
|
|
|
|
static LogContext ctx;
|
|
|
|
return ctx;
|
|
|
|
}
|
2018-05-28 13:49:44 +00:00
|
|
|
|
2019-06-10 13:20:48 +00:00
|
|
|
log_timestamp::log_timestamp() : log_timestamp("%c %Z")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
log_timestamp::log_timestamp(const char* fmt)
|
|
|
|
: format(fmt)
|
|
|
|
, now(llarp::time_now_ms())
|
|
|
|
, delta(llarp::time_now_ms() - LogContext::Instance().started)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-28 13:49:44 +00:00
|
|
|
void
|
|
|
|
SetLogLevel(LogLevel lvl)
|
|
|
|
{
|
2019-04-11 12:58:23 +00:00
|
|
|
LogContext::Instance().minLevel = lvl;
|
2018-05-28 13:49:44 +00:00
|
|
|
}
|
2018-07-09 03:34:29 +00:00
|
|
|
} // namespace llarp
|
2018-06-23 14:52:38 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
extern "C"
|
2018-06-23 14:52:38 +00:00
|
|
|
{
|
2018-08-02 00:48:43 +00:00
|
|
|
void
|
|
|
|
cSetLogLevel(LogLevel lvl)
|
|
|
|
{
|
|
|
|
llarp::SetLogLevel((llarp::LogLevel)lvl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cSetLogNodeName(const char* name)
|
|
|
|
{
|
2019-04-11 12:58:23 +00:00
|
|
|
llarp::LogContext::Instance().nodeName = name;
|
2018-08-02 00:48:43 +00:00
|
|
|
}
|
2018-12-12 02:52:51 +00:00
|
|
|
}
|