Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 27 additions & 2 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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
Expand Down Expand Up @@ -923,11 +924,27 @@ vector<string> 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),
Expand All @@ -940,7 +957,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);
}
Expand Down Expand Up @@ -1215,7 +1233,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<int>(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();
Expand Down