From a1d1518bc08404c7bec1aab8359739a07dea374c Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 8 Oct 2018 07:56:17 -0400 Subject: [PATCH] update logging to use human readable time --- include/llarp/dht/node.hpp | 4 ++-- include/llarp/link/server.hpp | 1 + include/llarp/link/session.hpp | 1 + include/llarp/logger.hpp | 15 +++++++++++++-- llarp/router_contact.cpp | 1 + llarp/time.cpp | 4 +--- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/llarp/dht/node.hpp b/include/llarp/dht/node.hpp index 3a56fa822..1ab44cbd8 100644 --- a/include/llarp/dht/node.hpp +++ b/include/llarp/dht/node.hpp @@ -29,7 +29,7 @@ namespace llarp bool operator<(const RCNode& other) const { - return rc.OtherIsNewer(other.rc); + return rc.last_updated < other.rc.last_updated; } }; @@ -53,7 +53,7 @@ namespace llarp bool operator<(const ISNode& other) const { - return introset.OtherIsNewer(other.introset); + return introset.T < other.introset.T; } }; } // namespace dht diff --git a/include/llarp/link/server.hpp b/include/llarp/link/server.hpp index b06c70c53..fefe70341 100644 --- a/include/llarp/link/server.hpp +++ b/include/llarp/link/server.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include struct llarp_router; diff --git a/include/llarp/link/session.hpp b/include/llarp/link/session.hpp index 8224d6eb6..f2d3e29d3 100644 --- a/include/llarp/link/session.hpp +++ b/include/llarp/link/session.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace llarp diff --git a/include/llarp/logger.hpp b/include/llarp/logger.hpp index 199dbea1e..6a40a5a01 100644 --- a/include/llarp/logger.hpp +++ b/include/llarp/logger.hpp @@ -1,6 +1,6 @@ #ifndef LLARP_LOGGER_HPP #define LLARP_LOGGER_HPP -#include +#include #include #include #include @@ -79,6 +79,17 @@ namespace llarp return std::to_string(id); } + struct log_timestamp + { + std::string format = "%c %Z"; + friend + std::ostream & operator << (std::ostream & out, const log_timestamp & ts) + { + auto now = llarp::Clock_t::to_time_t(llarp::Clock_t::now()); + return out << std::put_time(std::localtime(&now), ts.format.c_str()); + } + }; + /** internal */ template < typename... TArgs > void @@ -132,7 +143,7 @@ namespace llarp #endif std::string tag = fname; ss << _glog.nodeName << " (" << thread_id_string() << ") " - << llarp_time_now_ms() << " " << tag << ":" << lineno; + << log_timestamp() << " " << tag << ":" << lineno; ss << "\t"; LogAppend(ss, std::forward< TArgs >(args)...); #ifndef ANDROID diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 19c18e7a8..8f617fd43 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "buffer.hpp" #include "logger.hpp" #include "mem.hpp" diff --git a/llarp/time.cpp b/llarp/time.cpp index f012e70a5..6ec997cec 100644 --- a/llarp/time.cpp +++ b/llarp/time.cpp @@ -1,10 +1,8 @@ #include -#include +#include namespace llarp { - typedef std::chrono::system_clock Clock_t; - template < typename Res > static llarp_time_t time_since_epoch()