fix up logging, put _log into anonynous namespace, make only log trace nop in release builds

pull/1638/head
Jeff Becker 3 years ago
parent 20814a4adc
commit cf187ddffc
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -78,34 +78,36 @@ namespace llarp
LogLevel
GetLogLevel();
/** internal */
template <typename... TArgs>
inline static void
_log(LogLevel lvl, const slns::source_location& location, TArgs&&... args) noexcept
namespace
{
auto& log = LogContext::Instance();
if (log.curLevel > lvl || log.logStream == nullptr)
return;
std::ostringstream ss;
if constexpr (sizeof...(args) > 0)
LogAppend(ss, std::forward<TArgs>(args)...);
log.logStream->AppendLog(
lvl,
strip_prefix(location.file_name(), SOURCE_ROOT),
location.line(),
log.nodeName,
ss.str());
}
/** internal */
template <typename... TArgs>
inline static void
_log(LogLevel lvl, const slns::source_location& location, TArgs&&... args) noexcept
{
auto& log = LogContext::Instance();
if (log.curLevel > lvl || log.logStream == nullptr)
return;
std::ostringstream ss;
if constexpr (sizeof...(args) > 0)
LogAppend(ss, std::forward<TArgs>(args)...);
log.logStream->AppendLog(
lvl,
strip_prefix(location.file_name(), SOURCE_ROOT),
location.line(),
log.nodeName,
ss.str());
}
} // namespace
template <typename... T>
struct LogTrace
{
LogTrace(T... args, const slns::source_location& location = slns::source_location::current())
LogTrace(
[[maybe_unused]] T... args,
[[maybe_unused]] const slns::source_location& location = slns::source_location::current())
{
#ifdef NDEBUG
const auto discard = [](auto&&...) {};
discard(location, std::forward<T>(args)...);
#else
#ifndef NDEBUG
_log(eLogTrace, location, std::forward<T>(args)...);
#endif
}
@ -119,12 +121,7 @@ namespace llarp
{
LogDebug(T... args, const slns::source_location& location = slns::source_location::current())
{
#ifdef NDEBUG
const auto discard = [](auto&&...) {};
discard(location, std::forward<T>(args)...);
#else
_log(eLogDebug, location, std::forward<T>(args)...);
#endif
}
};

Loading…
Cancel
Save