Replace abseil date code with Hinnart's date.h

Howard Hinnart's date.h is the library that was accepted as C++20
date/calendar support, so this is essentially a backport of C++20 date
time support.

(It does support timezone support, but requires more of the library and
that seems like overkill for what we need; this just prints UTC
timestamps instead, which need only a header-only include).
pull/1124/head
Jason Rhinelander 4 years ago
parent ba1b20153e
commit 2e9840ea39

3
.gitmodules vendored

@ -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

@ -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)

1
external/date vendored

@ -0,0 +1 @@
Subproject commit 9a0ee2542848ab8625984fc8cdbfb9b5414c0082

@ -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

@ -0,0 +1,15 @@
#include <util/logging/logger_internal.hpp>
#include <date/date.h>
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

@ -3,28 +3,23 @@
#include <util/time.hpp>
#include <absl/time/clock.h>
#include <absl/time/time.h>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <util/thread/threading.hpp>
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

Loading…
Cancel
Save