mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
fix up logging, put _log into anonynous namespace, make only log trace nop in release builds
This commit is contained in:
parent
20814a4adc
commit
cf187ddffc
@ -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…
Reference in New Issue
Block a user