diff --git a/.gitmodules b/.gitmodules index d786b85b9..f1dd7f8da 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "external/optional-lite"] path = external/optional-lite url = https://github.com/martinmoene/optional-lite.git +[submodule "external/date"] + path = external/date + url = https://github.com/HowardHinnant/date.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2780480dc..e80d40421 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,7 @@ if(SUBMODULE_CHECK) check_submodule(external/cxxopts) check_submodule(external/ghc-filesystem) check_submodule(external/optional-lite) + check_submodule(external/date) endif() endif() @@ -268,6 +269,7 @@ add_subdirectory(external/nlohmann EXCLUDE_FROM_ALL) add_subdirectory(external/cxxopts) add_subdirectory(external/ghc-filesystem) add_subdirectory(external/optional-lite) +add_subdirectory(external/date) if(ANDROID) list(APPEND LIBS log) diff --git a/external/date b/external/date new file mode 160000 index 000000000..9a0ee2542 --- /dev/null +++ b/external/date @@ -0,0 +1 @@ +Subproject commit 9a0ee2542848ab8625984fc8cdbfb9b5414c0082 diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 7a143f865..26f863d9c 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -15,6 +15,7 @@ set(LIB_UTIL_SRC util/logging/file_logger.cpp util/logging/json_logger.cpp util/logging/logger.cpp + util/logging/logger_internal.cpp util/logging/loglevel.cpp util/logging/ostream_logger.cpp util/logging/syslog_logger.cpp @@ -42,10 +43,11 @@ endif() target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${LOG_LIB} ${CURL_LIBRARIES}) target_link_libraries(${UTIL_LIB} PUBLIC - absl::time absl::hash + absl::hash nlohmann_json::nlohmann_json ghc_filesystem optional-lite + date::date ) # cut back on fluff diff --git a/llarp/util/logging/logger_internal.cpp b/llarp/util/logging/logger_internal.cpp new file mode 100644 index 000000000..c28a20dfc --- /dev/null +++ b/llarp/util/logging/logger_internal.cpp @@ -0,0 +1,15 @@ +#include + +#include + +namespace llarp +{ + std::ostream& + operator<<(std::ostream& out, const log_timestamp& ts) + { + std::chrono::time_point< std::chrono::system_clock, + std::chrono::milliseconds > + now{std::chrono::milliseconds{ts.now}}; + return date::operator<<(out, now) << " UTC [+" << ts.delta << " ms]"; + } +} // namespace llarp diff --git a/llarp/util/logging/logger_internal.hpp b/llarp/util/logging/logger_internal.hpp index 293569a99..b502d2bc5 100644 --- a/llarp/util/logging/logger_internal.hpp +++ b/llarp/util/logging/logger_internal.hpp @@ -3,28 +3,23 @@ #include -#include -#include #include -#include #include #include namespace llarp { - /** internal */ - template < typename TArg > - void - LogAppend(std::stringstream& ss, TArg&& arg) noexcept + /** internal, recursion terminator */ + constexpr void + LogAppend(std::stringstream&) noexcept { - ss << std::forward< TArg >(arg); } /** internal */ template < typename TArg, typename... TArgs > void LogAppend(std::stringstream& ss, TArg&& arg, TArgs&&... args) noexcept { - LogAppend(ss, std::forward< TArg >(arg)); + ss << std::forward< TArg >(arg); LogAppend(ss, std::forward< TArgs >(args)...); } @@ -54,18 +49,8 @@ namespace llarp explicit log_timestamp(const char* fmt); }; - inline std::ostream& - operator<<(std::ostream& out, const log_timestamp& ts) - { -#if defined(ANDROID) || defined(RPI) - (void)ts; - return out << ts.now << " [+" << ts.delta << " ms]"; -#else - absl::TimeZone tz = absl::LocalTimeZone(); - return out << absl::FormatTime(ts.format, absl::FromUnixMillis(ts.now), tz) - << " [+" << ts.delta << " ms]"; -#endif - } + std::ostream& + operator<<(std::ostream& out, const log_timestamp& ts); } // namespace llarp