diff options
author | Elliott Hughes <enh@google.com> | 2016-06-21 14:25:44 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-06-21 14:27:16 -0700 |
commit | 4e5fd111d84de8f9b0f80a822a29b873921cf75f (patch) | |
tree | 1db6c701197478eadf5e4d7824e9b1b5fc52ca7c /base/logging.cpp | |
parent | 863d8e11b9b62388d9d00d7192b5e6f39fa089fa (diff) | |
download | system_core-4e5fd111d84de8f9b0f80a822a29b873921cf75f.tar.gz system_core-4e5fd111d84de8f9b0f80a822a29b873921cf75f.tar.bz2 system_core-4e5fd111d84de8f9b0f80a822a29b873921cf75f.zip |
Add timestamps to libbase's stderr logging.
adb is the client that wants this, but I'm not aware of any client that
doesn't.
Bug: http://b/28467098
Test: tested manually with cat.
Change-Id: I82c3f7ddf466a67aedfbb9010e0939a44b71d3e5
Diffstat (limited to 'base/logging.cpp')
-rw-r--r-- | base/logging.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/base/logging.cpp b/base/logging.cpp index 174187149..769c266c9 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -21,6 +21,7 @@ #include "android-base/logging.h" #include <libgen.h> +#include <time.h> // For getprogname(3) or program_invocation_short_name. #if defined(__ANDROID__) || defined(__APPLE__) @@ -186,12 +187,24 @@ static const char* ProgramInvocationName() { void StderrLogger(LogId, LogSeverity severity, const char*, 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 + + char timestamp[32]; + strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now); + static const char log_characters[] = "VDIWEF"; static_assert(arraysize(log_characters) - 1 == FATAL + 1, "Mismatch in size of log_characters and values in LogSeverity"); char severity_char = log_characters[severity]; - fprintf(stderr, "%s %c %5d %5d %s:%u] %s\n", ProgramInvocationName(), - severity_char, getpid(), GetThreadId(), file, line, message); + fprintf(stderr, "%s %c %s %5d %5d %s:%u] %s\n", ProgramInvocationName(), + severity_char, timestamp, getpid(), GetThreadId(), file, line, message); } |