2022-07-16 00:41:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Header for making actual log statements such as llarp::log::Info and so on work.
|
|
|
|
|
|
|
|
#include <oxen/log.hpp>
|
2022-09-28 16:37:19 +00:00
|
|
|
#include <oxen/log/ring_buffer_sink.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2022-07-16 00:41:14 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace log = oxen::log;
|
|
|
|
}
|
|
|
|
|
2023-09-29 21:00:13 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static auto util_cat = llarp::log::Cat("lokinet.util");
|
|
|
|
} // namespace
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
// Not ready to pollute these deprecation warnings everywhere yet
|
|
|
|
#if 0
|
|
|
|
#define LOKINET_LOG_DEPRECATED(Meth) \
|
|
|
|
[[deprecated("Use formatted log::" #Meth "(cat, fmt, args...) instead")]]
|
|
|
|
#else
|
|
|
|
#define LOKINET_LOG_DEPRECATED(Meth)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Deprecated loggers (in the top-level llarp namespace):
|
|
|
|
namespace llarp
|
|
|
|
{
|
2022-09-28 16:37:19 +00:00
|
|
|
inline std::shared_ptr<log::RingBufferSink> logRingBuffer = nullptr;
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
namespace log_detail
|
|
|
|
{
|
|
|
|
inline log::CategoryLogger legacy_logger = log::Cat("");
|
|
|
|
|
|
|
|
template <typename>
|
|
|
|
struct concat_args_fmt_impl;
|
|
|
|
template <size_t... I>
|
|
|
|
struct concat_args_fmt_impl<std::integer_sequence<size_t, I...>>
|
|
|
|
{
|
|
|
|
constexpr static std::array<char, sizeof...(I)> format{(I % 2 == 0 ? '{' : '}')...};
|
|
|
|
};
|
|
|
|
template <size_t N>
|
|
|
|
constexpr std::string_view
|
|
|
|
concat_args_fmt()
|
|
|
|
{
|
|
|
|
return std::string_view{
|
|
|
|
concat_args_fmt_impl<std::make_index_sequence<2 * N>>::format.data(), 2 * N};
|
|
|
|
}
|
|
|
|
} // namespace log_detail
|
|
|
|
|
|
|
|
template <typename... T>
|
2022-07-18 16:07:33 +00:00
|
|
|
struct LOKINET_LOG_DEPRECATED(Trace) LogTrace : log::trace<T...>
|
2022-07-16 00:41:14 +00:00
|
|
|
{
|
2022-07-18 16:07:33 +00:00
|
|
|
LogTrace(
|
|
|
|
T&&... args,
|
|
|
|
const log::slns::source_location& location = log::slns::source_location::current())
|
|
|
|
: log::trace<T...>::trace{
|
|
|
|
log_detail::legacy_logger,
|
|
|
|
log_detail::concat_args_fmt<sizeof...(T)>(),
|
|
|
|
std::forward<T>(args)...,
|
|
|
|
location}
|
|
|
|
{}
|
2022-07-16 00:41:14 +00:00
|
|
|
};
|
|
|
|
template <typename... T>
|
2022-07-18 16:07:33 +00:00
|
|
|
struct LOKINET_LOG_DEPRECATED(Debug) LogDebug : log::debug<T...>
|
2022-07-16 00:41:14 +00:00
|
|
|
{
|
2022-07-18 16:07:33 +00:00
|
|
|
LogDebug(
|
|
|
|
T&&... args,
|
|
|
|
const log::slns::source_location& location = log::slns::source_location::current())
|
|
|
|
: log::debug<T...>::debug{
|
|
|
|
log_detail::legacy_logger,
|
|
|
|
log_detail::concat_args_fmt<sizeof...(T)>(),
|
|
|
|
std::forward<T>(args)...,
|
|
|
|
location}
|
|
|
|
{}
|
2022-07-16 00:41:14 +00:00
|
|
|
};
|
|
|
|
template <typename... T>
|
2022-07-18 16:07:33 +00:00
|
|
|
struct LOKINET_LOG_DEPRECATED(Info) LogInfo : log::info<T...>
|
2022-07-16 00:41:14 +00:00
|
|
|
{
|
2022-07-18 16:07:33 +00:00
|
|
|
LogInfo(
|
|
|
|
T&&... args,
|
|
|
|
const log::slns::source_location& location = log::slns::source_location::current())
|
|
|
|
: log::info<T...>::info{
|
|
|
|
log_detail::legacy_logger,
|
|
|
|
log_detail::concat_args_fmt<sizeof...(T)>(),
|
|
|
|
std::forward<T>(args)...,
|
|
|
|
location}
|
|
|
|
{}
|
2022-07-16 00:41:14 +00:00
|
|
|
};
|
|
|
|
template <typename... T>
|
2022-07-18 16:07:33 +00:00
|
|
|
struct LOKINET_LOG_DEPRECATED(Warning) LogWarn : log::warning<T...>
|
2022-07-16 00:41:14 +00:00
|
|
|
{
|
2022-07-18 16:07:33 +00:00
|
|
|
LogWarn(
|
|
|
|
T&&... args,
|
|
|
|
const log::slns::source_location& location = log::slns::source_location::current())
|
|
|
|
: log::warning<T...>::warning{
|
|
|
|
log_detail::legacy_logger,
|
|
|
|
log_detail::concat_args_fmt<sizeof...(T)>(),
|
|
|
|
std::forward<T>(args)...,
|
|
|
|
location}
|
|
|
|
{}
|
2022-07-16 00:41:14 +00:00
|
|
|
};
|
|
|
|
template <typename... T>
|
2022-07-18 16:07:33 +00:00
|
|
|
struct LOKINET_LOG_DEPRECATED(Error) LogError : log::error<T...>
|
2022-07-16 00:41:14 +00:00
|
|
|
{
|
2022-07-18 16:07:33 +00:00
|
|
|
LogError(
|
|
|
|
T&&... args,
|
|
|
|
const log::slns::source_location& location = log::slns::source_location::current())
|
|
|
|
: log::error<T...>::error{
|
|
|
|
log_detail::legacy_logger,
|
|
|
|
log_detail::concat_args_fmt<sizeof...(T)>(),
|
|
|
|
std::forward<T>(args)...,
|
|
|
|
location}
|
|
|
|
{}
|
2022-07-16 00:41:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
LogTrace(T&&...) -> LogTrace<T...>;
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
LogDebug(T&&...) -> LogDebug<T...>;
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
LogInfo(T&&...) -> LogInfo<T...>;
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
LogWarn(T&&...) -> LogWarn<T...>;
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
LogError(T&&...) -> LogError<T...>;
|
|
|
|
|
|
|
|
} // namespace llarp
|