provide backward compatible send overload
This commit is contained in:
parent
c575116051
commit
dfb9ffc324
@ -154,9 +154,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
|||||||
# generated for Bazel.
|
# generated for Bazel.
|
||||||
"@bazel_tools//src/conditions:windows": [
|
"@bazel_tools//src/conditions:windows": [
|
||||||
"GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)",
|
"GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)",
|
||||||
|
"GLOG_DEPRECATED=__declspec(deprecated)",
|
||||||
"GLOG_NO_ABBREVIATED_SEVERITIES",
|
"GLOG_NO_ABBREVIATED_SEVERITIES",
|
||||||
],
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [
|
||||||
|
"GLOG_DEPRECATED=__attribute__((deprecated))",
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
copts =
|
copts =
|
||||||
select({
|
select({
|
||||||
|
|||||||
@ -133,23 +133,17 @@ typedef unsigned __int64 uint64;
|
|||||||
#error Do not know how to define a 32-bit integer quantity on your system
|
#error Do not know how to define a 32-bit integer quantity on your system
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ac_google_end_namespace@
|
typedef double WallTime;
|
||||||
|
|
||||||
struct GOOGLE_GLOG_DLL_DECL LogMessageTime {
|
struct GOOGLE_GLOG_DLL_DECL LogMessageTime {
|
||||||
LogMessageTime(): time_struct_(), timestamp_(0), usecs_(0), gmtoffset_(0) {}
|
LogMessageTime();
|
||||||
|
LogMessageTime(std::tm t);
|
||||||
void setTimeInfo(struct::tm time_struct, time_t timestamp, int32_t usecs){
|
LogMessageTime(std::time_t timestamp, WallTime now);
|
||||||
time_struct_ = time_struct;
|
|
||||||
timestamp_ = timestamp;
|
|
||||||
usecs_ = usecs;
|
|
||||||
|
|
||||||
CalcGmtOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
const time_t& timestamp() const { return timestamp_; }
|
const time_t& timestamp() const { return timestamp_; }
|
||||||
const int& sec() const { return time_struct_.tm_sec; }
|
const int& sec() const { return time_struct_.tm_sec; }
|
||||||
const int32_t& usec() const { return usecs_; }
|
const int32_t& usec() const { return usecs_; }
|
||||||
const int& (min)() const { return time_struct_.tm_min; }
|
const int&(min)() const { return time_struct_.tm_min; }
|
||||||
const int& hour() const { return time_struct_.tm_hour; }
|
const int& hour() const { return time_struct_.tm_hour; }
|
||||||
const int& day() const { return time_struct_.tm_mday; }
|
const int& day() const { return time_struct_.tm_mday; }
|
||||||
const int& month() const { return time_struct_.tm_mon; }
|
const int& month() const { return time_struct_.tm_mon; }
|
||||||
@ -158,14 +152,16 @@ struct GOOGLE_GLOG_DLL_DECL LogMessageTime {
|
|||||||
const int& dayInYear() const { return time_struct_.tm_yday; }
|
const int& dayInYear() const { return time_struct_.tm_yday; }
|
||||||
const int& dst() const { return time_struct_.tm_isdst; }
|
const int& dst() const { return time_struct_.tm_isdst; }
|
||||||
const long int& gmtoff() const { return gmtoffset_; }
|
const long int& gmtoff() const { return gmtoffset_; }
|
||||||
|
const std::tm& tm() const { return time_struct_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct::tm time_struct_; // Time of creation of LogMessage
|
void init(const std::tm& t, std::time_t timestamp, WallTime now);
|
||||||
time_t timestamp_; // Time of creation of LogMessage in seconds
|
std::tm time_struct_; // Time of creation of LogMessage
|
||||||
int32_t usecs_; // Time of creation of LogMessage - microseconds part
|
time_t timestamp_; // Time of creation of LogMessage in seconds
|
||||||
long int gmtoffset_;
|
int32_t usecs_; // Time of creation of LogMessage - microseconds part
|
||||||
|
long int gmtoffset_;
|
||||||
|
|
||||||
void CalcGmtOffset();
|
void CalcGmtOffset();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef GLOG_CUSTOM_PREFIX_SUPPORT
|
#ifdef GLOG_CUSTOM_PREFIX_SUPPORT
|
||||||
@ -187,8 +183,12 @@ struct LogMessageInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, void* data);
|
typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, void* data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ac_google_end_namespace@
|
||||||
|
|
||||||
|
|
||||||
// The global value of GOOGLE_STRIP_LOG. All the messages logged to
|
// The global value of GOOGLE_STRIP_LOG. All the messages logged to
|
||||||
// LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
|
// LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
|
||||||
// If it can be determined at compile time that the message will not be
|
// If it can be determined at compile time that the message will not be
|
||||||
@ -1562,9 +1562,7 @@ public:
|
|||||||
// Must be called without the log_mutex held. (L < log_mutex)
|
// Must be called without the log_mutex held. (L < log_mutex)
|
||||||
static int64 num_messages(int severity);
|
static int64 num_messages(int severity);
|
||||||
|
|
||||||
const LogMessageTime& getLogMessageTime() const {
|
const LogMessageTime& getLogMessageTime() const;
|
||||||
return logmsgtime_;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct LogMessageData;
|
struct LogMessageData;
|
||||||
|
|
||||||
@ -1736,8 +1734,13 @@ class GOOGLE_GLOG_DLL_DECL LogSink {
|
|||||||
// during this call.
|
// during this call.
|
||||||
virtual void send(LogSeverity severity, const char* full_filename,
|
virtual void send(LogSeverity severity, const char* full_filename,
|
||||||
const char* base_filename, int line,
|
const char* base_filename, int line,
|
||||||
const LogMessageTime &logmsgtime,
|
const LogMessageTime& logmsgtime, const char* message,
|
||||||
const char* message, size_t message_len) = 0;
|
size_t message_len);
|
||||||
|
// Provide an overload for compatibility purposes
|
||||||
|
GLOG_DEPRECATED
|
||||||
|
virtual void send(LogSeverity severity, const char* full_filename,
|
||||||
|
const char* base_filename, int line, const std::tm* t,
|
||||||
|
const char* message, size_t message_len);
|
||||||
|
|
||||||
// Redefine this to implement waiting for
|
// Redefine this to implement waiting for
|
||||||
// the sink's logging logic to complete.
|
// the sink's logging logic to complete.
|
||||||
|
|||||||
114
src/logging.cc
114
src/logging.cc
@ -487,8 +487,7 @@ class LogCleaner {
|
|||||||
bool enabled() const { return enabled_; }
|
bool enabled() const { return enabled_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<string> GetOverdueLogNames(string log_directory,
|
vector<string> GetOverdueLogNames(string log_directory, unsigned int days,
|
||||||
unsigned int days,
|
|
||||||
const string& base_filename,
|
const string& base_filename,
|
||||||
const string& filename_extension) const;
|
const string& filename_extension) const;
|
||||||
|
|
||||||
@ -496,8 +495,7 @@ class LogCleaner {
|
|||||||
const string& base_filename,
|
const string& base_filename,
|
||||||
const string& filename_extension) const;
|
const string& filename_extension) const;
|
||||||
|
|
||||||
bool IsLogLastModifiedOver(const string& filepath,
|
bool IsLogLastModifiedOver(const string& filepath, unsigned int days) const;
|
||||||
unsigned int days) const;
|
|
||||||
|
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
unsigned int overdue_days_;
|
unsigned int overdue_days_;
|
||||||
@ -567,12 +565,9 @@ class LogDestination {
|
|||||||
const char* message, size_t len);
|
const char* message, size_t len);
|
||||||
|
|
||||||
// Send logging info to all registered sinks.
|
// Send logging info to all registered sinks.
|
||||||
static void LogToSinks(LogSeverity severity,
|
static void LogToSinks(LogSeverity severity, const char* full_filename,
|
||||||
const char *full_filename,
|
const char* base_filename, int line,
|
||||||
const char *base_filename,
|
const LogMessageTime& logmsgtime, const char* message,
|
||||||
int line,
|
|
||||||
const LogMessageTime &logmsgtime,
|
|
||||||
const char* message,
|
|
||||||
size_t message_len);
|
size_t message_len);
|
||||||
|
|
||||||
// Wait for all registered sinks via WaitTillSent
|
// Wait for all registered sinks via WaitTillSent
|
||||||
@ -850,10 +845,9 @@ inline void LogDestination::LogToAllLogfiles(LogSeverity severity,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void LogDestination::LogToSinks(LogSeverity severity,
|
inline void LogDestination::LogToSinks(LogSeverity severity,
|
||||||
const char *full_filename,
|
const char* full_filename,
|
||||||
const char *base_filename,
|
const char* base_filename, int line,
|
||||||
int line,
|
const LogMessageTime& logmsgtime,
|
||||||
const LogMessageTime &logmsgtime,
|
|
||||||
const char* message,
|
const char* message,
|
||||||
size_t message_len) {
|
size_t message_len) {
|
||||||
ReaderMutexLock l(&sink_mutex_);
|
ReaderMutexLock l(&sink_mutex_);
|
||||||
@ -1134,10 +1128,11 @@ void LogFileObject::Write(bool force_flush,
|
|||||||
rollover_attempt_ = 0;
|
rollover_attempt_ = 0;
|
||||||
|
|
||||||
struct ::tm tm_time;
|
struct ::tm tm_time;
|
||||||
if (FLAGS_log_utc_time)
|
if (FLAGS_log_utc_time) {
|
||||||
gmtime_r(×tamp, &tm_time);
|
gmtime_r(×tamp, &tm_time);
|
||||||
else
|
} else {
|
||||||
localtime_r(×tamp, &tm_time);
|
localtime_r(×tamp, &tm_time);
|
||||||
|
}
|
||||||
|
|
||||||
// The logfile's filename will have the date/time & pid in it
|
// The logfile's filename will have the date/time & pid in it
|
||||||
ostringstream time_pid_stream;
|
ostringstream time_pid_stream;
|
||||||
@ -1343,10 +1338,9 @@ void LogCleaner::Run(bool base_filename_selected,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> LogCleaner::GetOverdueLogNames(string log_directory,
|
vector<string> LogCleaner::GetOverdueLogNames(
|
||||||
unsigned int days,
|
string log_directory, unsigned int days, const string& base_filename,
|
||||||
const string& base_filename,
|
const string& filename_extension) const {
|
||||||
const string& filename_extension) const {
|
|
||||||
// The names of overdue logs.
|
// The names of overdue logs.
|
||||||
vector<string> overdue_log_names;
|
vector<string> overdue_log_names;
|
||||||
|
|
||||||
@ -1605,14 +1599,7 @@ void LogMessage::Init(const char* file,
|
|||||||
data_->outvec_ = NULL;
|
data_->outvec_ = NULL;
|
||||||
WallTime now = WallTime_Now();
|
WallTime now = WallTime_Now();
|
||||||
time_t timestamp_now = static_cast<time_t>(now);
|
time_t timestamp_now = static_cast<time_t>(now);
|
||||||
std::tm time_struct;
|
logmsgtime_ = LogMessageTime(timestamp_now, now);
|
||||||
if(FLAGS_log_utc_time)
|
|
||||||
gmtime_r(×tamp_now, &time_struct);
|
|
||||||
else
|
|
||||||
localtime_r(×tamp_now, &time_struct);
|
|
||||||
|
|
||||||
logmsgtime_.setTimeInfo(time_struct, timestamp_now,
|
|
||||||
static_cast<int32>((now - timestamp_now) * 1000000));
|
|
||||||
|
|
||||||
data_->num_chars_to_log_ = 0;
|
data_->num_chars_to_log_ = 0;
|
||||||
data_->num_chars_to_syslog_ = 0;
|
data_->num_chars_to_syslog_ = 0;
|
||||||
@ -1674,6 +1661,10 @@ void LogMessage::Init(const char* file,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LogMessageTime& LogMessage::getLogMessageTime() const {
|
||||||
|
return logmsgtime_;
|
||||||
|
}
|
||||||
|
|
||||||
LogMessage::~LogMessage() {
|
LogMessage::~LogMessage() {
|
||||||
Flush();
|
Flush();
|
||||||
#ifdef GLOG_THREAD_LOCAL_STORAGE
|
#ifdef GLOG_THREAD_LOCAL_STORAGE
|
||||||
@ -2023,13 +2014,45 @@ void SetLogSymlink(LogSeverity severity, const char* symlink_basename) {
|
|||||||
LogSink::~LogSink() {
|
LogSink::~LogSink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogSink::send(LogSeverity severity, const char* full_filename,
|
||||||
|
const char* base_filename, int line,
|
||||||
|
const LogMessageTime& time, const char* message,
|
||||||
|
size_t message_len) {
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4996)
|
||||||
|
#endif // __GNUC__
|
||||||
|
send(severity, full_filename, base_filename, line, &time.tm(), message,
|
||||||
|
message_len);
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif // __GNUC__
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogSink::send(LogSeverity severity, const char* full_filename,
|
||||||
|
const char* base_filename, int line, const std::tm* t,
|
||||||
|
const char* message, size_t message_len) {
|
||||||
|
(void)severity;
|
||||||
|
(void)full_filename;
|
||||||
|
(void)base_filename;
|
||||||
|
(void)line;
|
||||||
|
(void)t;
|
||||||
|
(void)message;
|
||||||
|
(void)message_len;
|
||||||
|
}
|
||||||
|
|
||||||
void LogSink::WaitTillSent() {
|
void LogSink::WaitTillSent() {
|
||||||
// noop default
|
// noop default
|
||||||
}
|
}
|
||||||
|
|
||||||
string LogSink::ToString(LogSeverity severity, const char* file, int line,
|
string LogSink::ToString(LogSeverity severity, const char* file, int line,
|
||||||
const LogMessageTime &logmsgtime,
|
const LogMessageTime& logmsgtime, const char* message,
|
||||||
const char* message, size_t message_len) {
|
size_t message_len) {
|
||||||
ostringstream stream(string(message, message_len));
|
ostringstream stream(string(message, message_len));
|
||||||
stream.fill('0');
|
stream.fill('0');
|
||||||
|
|
||||||
@ -2559,7 +2582,31 @@ void DisableLogCleaner() {
|
|||||||
log_cleaner.Disable();
|
log_cleaner.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
_END_GOOGLE_NAMESPACE_
|
LogMessageTime::LogMessageTime()
|
||||||
|
: time_struct_(), timestamp_(0), usecs_(0), gmtoffset_(0) {}
|
||||||
|
|
||||||
|
LogMessageTime::LogMessageTime(std::tm t) {
|
||||||
|
std::time_t timestamp = std::mktime(&t);
|
||||||
|
init(t, timestamp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogMessageTime::LogMessageTime(std::time_t timestamp, WallTime now) {
|
||||||
|
std::tm t;
|
||||||
|
if (FLAGS_log_utc_time)
|
||||||
|
gmtime_r(×tamp, &t);
|
||||||
|
else
|
||||||
|
localtime_r(×tamp, &t);
|
||||||
|
init(t, timestamp, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogMessageTime::init(const std::tm& t, std::time_t timestamp,
|
||||||
|
WallTime now) {
|
||||||
|
time_struct_ = t;
|
||||||
|
timestamp_ = timestamp;
|
||||||
|
usecs_ = static_cast<int32>((now - timestamp) * 1000000);
|
||||||
|
|
||||||
|
CalcGmtOffset();
|
||||||
|
}
|
||||||
|
|
||||||
void LogMessageTime::CalcGmtOffset() {
|
void LogMessageTime::CalcGmtOffset() {
|
||||||
std::tm gmt_struct;
|
std::tm gmt_struct;
|
||||||
@ -2579,3 +2626,4 @@ void LogMessageTime::CalcGmtOffset() {
|
|||||||
gmtoffset_ = static_cast<long int>(timestamp_ - gmt_sec + (isDst ? hour_secs : 0) ) ;
|
gmtoffset_ = static_cast<long int>(timestamp_ - gmt_sec + (isDst ? hour_secs : 0) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_END_GOOGLE_NAMESPACE_
|
||||||
|
|||||||
@ -147,8 +147,6 @@ const char* ProgramInvocationShortName();
|
|||||||
int64 CycleClock_Now();
|
int64 CycleClock_Now();
|
||||||
|
|
||||||
int64 UsecToCycles(int64 usec);
|
int64 UsecToCycles(int64 usec);
|
||||||
|
|
||||||
typedef double WallTime;
|
|
||||||
WallTime WallTime_Now();
|
WallTime WallTime_Now();
|
||||||
|
|
||||||
int32 GetMainThreadPid();
|
int32 GetMainThreadPid();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user