lokinet/llarp/util/logging/logger_internal.hpp

58 lines
1.1 KiB
C++
Raw Normal View History

2019-04-11 12:58:23 +00:00
#ifndef LLARP_UTIL_LOGGER_INTERNAL_HPP
#define LLARP_UTIL_LOGGER_INTERNAL_HPP
2019-07-16 22:55:58 +00:00
#include <util/time.hpp>
2019-04-11 12:58:23 +00:00
#include <ctime>
2019-07-16 22:55:58 +00:00
#include <sstream>
2019-10-02 13:06:14 +00:00
#include <util/thread/threading.hpp>
2019-04-11 12:58:23 +00:00
namespace llarp
{
/** internal, recursion terminator */
constexpr void
LogAppend(std::stringstream&) noexcept
2019-04-11 12:58:23 +00:00
{
}
/** internal */
template <typename TArg, typename... TArgs>
2019-04-11 12:58:23 +00:00
void
LogAppend(std::stringstream& ss, TArg&& arg, TArgs&&... args) noexcept
{
ss << std::forward<TArg>(arg);
LogAppend(ss, std::forward<TArgs>(args)...);
2019-04-11 12:58:23 +00:00
}
2019-07-16 22:55:58 +00:00
inline std::string
2019-04-11 12:58:23 +00:00
thread_id_string()
{
auto tid = std::this_thread::get_id();
std::hash<std::thread::id> h;
2019-04-11 12:58:23 +00:00
uint16_t id = h(tid) % 1000;
#if defined(ANDROID) || defined(RPI)
char buff[8] = {0};
snprintf(buff, sizeof(buff), "%u", id);
return buff;
#else
return std::to_string(id);
#endif
}
struct log_timestamp
{
const char* format;
2019-06-10 13:20:48 +00:00
const llarp_time_t now;
const llarp_time_t delta;
2019-04-11 12:58:23 +00:00
2019-06-10 13:20:48 +00:00
log_timestamp();
2019-04-11 12:58:23 +00:00
2019-06-10 13:20:48 +00:00
explicit log_timestamp(const char* fmt);
2019-05-18 15:34:03 +00:00
};
std::ostream&
operator<<(std::ostream& out, const log_timestamp& ts);
2019-04-11 12:58:23 +00:00
} // namespace llarp
#endif