Add FLAGS_log_utc_time; when 'true' the time will be written in log in UTC
This commit is contained in:
parent
0a2e5931bd
commit
909069ea82
@ -142,6 +142,9 @@
|
||||
/* define if localtime_r is available in time.h */
|
||||
#cmakedefine HAVE_LOCALTIME_R
|
||||
|
||||
/* define if gmtime_r is available in time.h */
|
||||
#cmakedefine HAVE_GMTIME_R
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#cmakedefine LT_OBJDIR
|
||||
|
||||
@ -380,6 +380,9 @@ DECLARE_int32(max_log_size);
|
||||
// Sets whether to avoid logging to the disk if the disk is full.
|
||||
DECLARE_bool(stop_logging_if_full_disk);
|
||||
|
||||
// Use UTC time for logging
|
||||
DECLARE_bool(log_utc_time);
|
||||
|
||||
#ifdef MUST_UNDEF_GFLAGS_DECLARE_MACROS
|
||||
#undef MUST_UNDEF_GFLAGS_DECLARE_MACROS
|
||||
#undef DECLARE_VARIABLE
|
||||
|
||||
@ -187,6 +187,9 @@ GLOG_DEFINE_bool(stop_logging_if_full_disk, false,
|
||||
GLOG_DEFINE_string(log_backtrace_at, "",
|
||||
"Emit a backtrace when logging at file:linenum.");
|
||||
|
||||
GLOG_DEFINE_bool(log_utc_time, false,
|
||||
"Use UTC time for logging.");
|
||||
|
||||
// TODO(hamaji): consider windows
|
||||
#define PATH_SEPARATOR '/'
|
||||
|
||||
@ -1129,7 +1132,10 @@ void LogFileObject::Write(bool force_flush,
|
||||
rollover_attempt_ = 0;
|
||||
|
||||
struct ::tm tm_time;
|
||||
localtime_r(×tamp, &tm_time);
|
||||
if (FLAGS_log_utc_time)
|
||||
gmtime_r(×tamp, &tm_time);
|
||||
else
|
||||
localtime_r(×tamp, &tm_time);
|
||||
|
||||
// The logfile's filename will have the date/time & pid in it
|
||||
ostringstream time_pid_stream;
|
||||
@ -1213,7 +1219,7 @@ void LogFileObject::Write(bool force_flush,
|
||||
<< ' '
|
||||
<< setw(2) << tm_time.tm_hour << ':'
|
||||
<< setw(2) << tm_time.tm_min << ':'
|
||||
<< setw(2) << tm_time.tm_sec << '\n'
|
||||
<< setw(2) << tm_time.tm_sec << (FLAGS_log_utc_time ? " UTC\n" : "\n")
|
||||
<< "Running on machine: "
|
||||
<< LogDestination::hostname() << '\n'
|
||||
<< "Log line format: [IWEF]yyyymmdd hh:mm:ss.uuuuuu "
|
||||
@ -1418,7 +1424,10 @@ void LogMessage::Init(const char* file,
|
||||
data_->outvec_ = NULL;
|
||||
WallTime now = WallTime_Now();
|
||||
data_->timestamp_ = static_cast<time_t>(now);
|
||||
localtime_r(&data_->timestamp_, &data_->tm_time_);
|
||||
if(FLAGS_log_utc_time)
|
||||
gmtime_r(&data_->timestamp_, &data_->tm_time_);
|
||||
else
|
||||
localtime_r(&data_->timestamp_, &data_->tm_time_);
|
||||
data_->usecs_ = static_cast<int32>((now - data_->timestamp_) * 1000000);
|
||||
|
||||
data_->num_chars_to_log_ = 0;
|
||||
|
||||
@ -381,6 +381,9 @@ DECLARE_int32(max_log_size);
|
||||
// Sets whether to avoid logging to the disk if the disk is full.
|
||||
DECLARE_bool(stop_logging_if_full_disk);
|
||||
|
||||
// Use UTC time for logging.
|
||||
DECLARE_bool(log_utc_time);
|
||||
|
||||
#ifdef MUST_UNDEF_GFLAGS_DECLARE_MACROS
|
||||
#undef MUST_UNDEF_GFLAGS_DECLARE_MACROS
|
||||
#undef DECLARE_VARIABLE
|
||||
|
||||
@ -54,6 +54,12 @@ struct tm* localtime_r(const time_t* timep, struct tm* result) {
|
||||
return result;
|
||||
}
|
||||
#endif // not HAVE_LOCALTIME_R
|
||||
#ifndef HAVE_GMTIME_R
|
||||
struct tm* gmtime_r(const time_t* timep, struct tm* result) {
|
||||
gmtime_s(result, timep);
|
||||
return result;
|
||||
}
|
||||
#endif // not HAVE_GMTIME_R
|
||||
#ifndef HAVE_SNPRINTF
|
||||
int snprintf(char *str, size_t size, const char *format, ...) {
|
||||
va_list ap;
|
||||
|
||||
@ -159,6 +159,10 @@ enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock
|
||||
extern GOOGLE_GLOG_DLL_DECL struct tm* localtime_r(const time_t* timep, struct tm* result);
|
||||
#endif // not HAVE_LOCALTIME_R
|
||||
|
||||
#ifndef HAVE_GMTIME_R
|
||||
extern GOOGLE_GLOG_DLL_DECL struct tm* gmtime_r(const time_t* timep, struct tm* result);
|
||||
#endif // not HAVE_GMTIME_R
|
||||
|
||||
inline char* strerror_r(int errnum, char* buf, size_t buflen) {
|
||||
strerror_s(buf, buflen, errnum);
|
||||
return buf;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user