Skip to content

Commit

Permalink
Merge pull request #425 from plmuon/remove-time-from-raw-logging
Browse files Browse the repository at this point in the history
remove time from raw logging
  • Loading branch information
shinh committed Feb 2, 2019
2 parents 6404139 + e5588de commit 41f4bf9
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 26 deletions.
5 changes: 0 additions & 5 deletions src/glog/raw_logging.h.in
Expand Up @@ -175,11 +175,6 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
const char* format, ...)
@ac_cv___attribute___printf_4_5@;

// Hack to propagate time information into this module so that
// this module does not have to directly call localtime_r(),
// which could allocate memory.
GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);

@ac_google_end_namespace@

#endif // BASE_RAW_LOGGING_H_
1 change: 0 additions & 1 deletion src/logging.cc
Expand Up @@ -1266,7 +1266,6 @@ void LogMessage::Init(const char* file,
data_->timestamp_ = static_cast<time_t>(now);
localtime_r(&data_->timestamp_, &data_->tm_time_);
int usecs = static_cast<int>((now - data_->timestamp_) * 1000000);
RawLog__SetLastTime(data_->tm_time_, usecs);

data_->num_chars_to_log_ = 0;
data_->num_chars_to_syslog_ = 0;
Expand Down
16 changes: 1 addition & 15 deletions src/raw_logging.cc
Expand Up @@ -68,17 +68,6 @@

_START_GOOGLE_NAMESPACE_

// Data for RawLog__ below. We simply pick up the latest
// time data created by a normal log message to avoid calling
// localtime_r which can allocate memory.
static struct ::tm last_tm_time_for_raw_log;
static int last_usecs_for_raw_log;

void RawLog__SetLastTime(const struct ::tm& t, int usecs) {
memcpy(&last_tm_time_for_raw_log, &t, sizeof(last_tm_time_for_raw_log));
last_usecs_for_raw_log = usecs;
}

// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
// that invoke malloc() and getenv() that might acquire some locks.
// If this becomes a problem we should reimplement a subset of vsnprintf
Expand Down Expand Up @@ -120,16 +109,13 @@ void RawLog__(LogSeverity severity, const char* file, int line,
return; // this stderr log message is suppressed
}
// can't call localtime_r here: it can allocate
struct ::tm& t = last_tm_time_for_raw_log;
char buffer[kLogBufSize];
char* buf = buffer;
int size = sizeof(buffer);

// NOTE: this format should match the specification in base/logging.h
DoRawLog(&buf, &size, "%c%02d%02d %02d:%02d:%02d.%06d %5u %s:%d] RAW: ",
DoRawLog(&buf, &size, "%c0000 00:00:00.000000 %5u %s:%d] RAW: ",
LogSeverityNames[severity][0],
1 + t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
last_usecs_for_raw_log,
static_cast<unsigned int>(GetTID()),
const_basename(const_cast<char *>(file)), line);

Expand Down
5 changes: 0 additions & 5 deletions src/windows/glog/raw_logging.h
Expand Up @@ -179,11 +179,6 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
const char* format, ...)
;

// Hack to propagate time information into this module so that
// this module does not have to directly call localtime_r(),
// which could allocate memory.
GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);

}

#endif // BASE_RAW_LOGGING_H_

0 comments on commit 41f4bf9

Please sign in to comment.