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

Merge branch 'log-fill-remaining-nanos' into 'master'

[log] Improve timestamp format: HHMM.SS mmmuuunnn

See merge request i4/manycore/emper!360
parents 4d90dfc0 7416e2f9
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2021 Florian Fischer
// Copyright © 2020-2022 Florian Schmaus, Florian Fischer
#include "log.hpp"
#include <pthread.h>
......@@ -44,15 +43,15 @@ static void add_timestamp_to(std::ostringstream& logMessage) {
}
}();
logMessage << std::put_time(now_localtime, "%H%M.");
logMessage << std::put_time(now_localtime, "%H%M.%S");
auto now_nanos = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
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;
constexpr long NanosInASecond = 1000L * 1000 * 1000;
long remaining_nanos = time_since_epoch_long % NanosInASecond;
logMessage << " " << std::setfill('0') << std::setw(9) << remaining_nanos;
}
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