libbase output in host now look similar to the logcat output on device
I8189501d123fb79a255e17f675f8f6be617022e8 changed the output format of
host-side liblog. This change does the same for libbase.
For some unknown reason I don't fully understand, libbase has formatted
host-side logs by itself without relying on liblog. (note that libbase
"always" depends on liblog even for hosts. A follow-up might be reduce
the code duplication across libbase and liblog.
Bug: 287910948
Test: see the host logs
Test: atest --host libbase_test:logging_splitters
Test: atest --host libbase_test:logging
Test: atest --host libblog-host-test
Change-Id: Ie220d78a1c15686be7ae34cd5be88b858903f2e1
diff --git a/logging.cpp b/logging.cpp
index e6c02ba..b296d3b 100644
--- a/logging.cpp
+++ b/logging.cpp
@@ -277,16 +277,10 @@
void StderrLogger(LogId, LogSeverity severity, const char* tag, const char* file, unsigned int line,
const char* message) {
- struct tm now;
- time_t t = time(nullptr);
-
-#if defined(_WIN32)
- localtime_s(&now, &t);
-#else
- localtime_r(&t, &now);
-#endif
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
auto output_string =
- StderrOutputGenerator(now, getpid(), GetThreadId(), severity, tag, file, line, message);
+ StderrOutputGenerator(ts, getpid(), GetThreadId(), severity, tag, file, line, message);
fputs(output_string.c_str(), stderr);
}