diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 8901b9c..19b5462 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -529,7 +529,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)()); // Enable/Disable old log cleaner. GOOGLE_GLOG_DLL_DECL void EnableLogCleaner(int overdue_days); GOOGLE_GLOG_DLL_DECL void DisableLogCleaner(); - +GOOGLE_GLOG_DLL_DECL void SetApplicationFingerprint(const std::string& fingerprint); class LogSink; // defined below diff --git a/src/logging.cc b/src/logging.cc index 6d31481..9d65528 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -454,6 +454,7 @@ class LogFileObject : public base::Logger { uint32 file_length_; unsigned int rollover_attempt_; int64 next_flush_time_; // cycle count at which to flush log + WallTime start_time_; // Actually create a logfile using the value of base_filename_ and the // optional argument time_pid_string @@ -938,11 +939,27 @@ vector GetOverdueLogNames(string log_directory, int days) { bool log_cleaner_enabled_; int log_cleaner_overdue_days_ = 7; +std::string g_application_fingerprint; + } // namespace +void SetApplicationFingerprint(const std::string& fingerprint) { + g_application_fingerprint = fingerprint; +} namespace { +string PrettyDuration(int secs) { + std::stringstream result; + int mins = secs / 60; + int hours = mins / 60; + mins = mins % 60; + secs = secs % 60; + result.fill('0'); + result << hours << ':' << setw(2) << mins << ':' << setw(2) << secs; + return result.str(); +} + LogFileObject::LogFileObject(LogSeverity severity, const char* base_filename) : base_filename_selected_(base_filename != NULL), @@ -955,7 +972,8 @@ LogFileObject::LogFileObject(LogSeverity severity, dropped_mem_length_(0), file_length_(0), rollover_attempt_(kRolloverAttemptFrequency-1), - next_flush_time_(0) { + next_flush_time_(0), + start_time_(WallTime_Now()) { assert(severity >= 0); assert(severity < NUM_SEVERITIES); } @@ -1230,7 +1248,14 @@ void LogFileObject::Write(bool force_flush, << setw(2) << tm_time.tm_min << ':' << setw(2) << tm_time.tm_sec << '\n' << "Running on machine: " - << LogDestination::hostname() << '\n' + << LogDestination::hostname() << '\n'; + + if(!g_application_fingerprint.empty()) { + file_header_stream << "Application fingerprint: " << g_application_fingerprint << '\n'; + } + + file_header_stream << "Running duration (h:mm:ss): " + << PrettyDuration(static_cast(WallTime_Now() - start_time_)) << '\n' << "Log line format: [IWEF]yyyymmdd hh:mm:ss.uuuuuu " << "threadid file:line] msg" << '\n'; const string& file_header_string = file_header_stream.str();