Skip to content
Snippets Groups Projects
Commit f32104a4 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[log] Use system_clock instead of high_resolution_clock

According to the 'Notes' section of
https://en.cppreference.com/w/cpp/chrono/high_resolution_clock one
should just use steady_clock or system_clock. Furthermore, the notes
state that with GCC's libstdc++ high_resolution_clock is system_clock,
but for LLVM's libc++ it depends on the configuration (and is
steady_clock). But steady_clock has no to_time_t() member function.

Hence we explicitly uses system_clock now, which always has
to_time_t(), i.e. in libstdc++ and in libc++. This allows us to get
rid of the GLIBCXX (libstdc++) specific code.
parent 0bd272ba
No related branches found
No related tags found
1 merge request!309[log] Use system_clock instead of high_resolution_clock
......@@ -24,12 +24,10 @@ using emper::io::GlobalIoContext;
namespace emper::log {
static void add_timestamp_to(std::ostringstream& logMessage) {
#if defined __GLIBCXX__
static const long NanosInAMinute = 60L * 1000 * 1000 * 1000;
using clock = std::chrono::system_clock;
auto now = std::chrono::high_resolution_clock::now();
auto now_time_t = std::chrono::high_resolution_clock::to_time_t(now);
auto now = clock::now();
auto now_time_t = clock::to_time_t(now);
const std::tm* now_localtime = [&now_time_t] {
if constexpr (emper::LOG_TIMESTAMP == emper::LogTimeStamp::utc) {
......@@ -52,11 +50,9 @@ static void add_timestamp_to(std::ostringstream& logMessage) {
auto time_since_epoch = now_nanos.time_since_epoch();
long time_since_epoch_long = time_since_epoch.count();
const long NanosInAMinute = 60L * 1000 * 1000 * 1000;
long remaining_nanos = time_since_epoch_long % NanosInAMinute;
logMessage << remaining_nanos;
#else
logMessage << "UNKN_TIME";
#endif
}
static std::mutex log_mutex;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment