<h3><A NAME=windows>Notes for Windows users</A></h3>
<p>Google glog defines a severity level <code>ERROR</code>, which is
-also defined in <code>windows.h</code>
-There are two known workarounds to avoid this conflict:
+also defined in <code>windows.h</code> . You can make glog not define
+<code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
+and <code>FATAL</code> by defining
+<code>GLOG_NO_ABBREVIATED_SEVERITIES</code> before
+including <code>glog/logging.h</code> . Even with this macro, you can
+still use the iostream like logging facilities:
+
+<pre>
+ #define GLOG_NO_ABBREVIATED_SEVERITIES
+ #include <windows.h>
+ #include <glog/logging.h>
+
+ // ...
+
+ LOG(ERROR) << "This should work";
+ LOG_IF(ERROR, x > y) << "This should be also OK";
+</pre>
+
+<p>
+However, you cannot
+use <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
+and <code>FATAL</code> anymore for functions defined
+in <code>glog/logging.h</code> .
+
+<pre>
+ #define GLOG_NO_ABBREVIATED_SEVERITIES
+ #include <windows.h>
+ #include <glog/logging.h>
+
+ // ...
+
+ // This won't work.
+ // google::FlushLogFiles(google::ERROR);
+
+ // Use this instead.
+ google::FlushLogFiles(google::GLOG_ERROR);
+</pre>
+
+<p>
+If you don't need <code>ERROR</code> defined
+by <code>windows.h</code>, there are a couple of more workarounds
+which sometimes don't work:
<ul>
<li>#define <code>WIN32_LEAN_AND_MEAN</code> or <code>NOGDI</code>
// you ever need to change their values or add a new severity.
typedef int LogSeverity;
-const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4;
+const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
+ NUM_SEVERITIES = 4;
+#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
+# ifdef ERROR
+# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
+# endif
+const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
+ ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
+#endif
// DFATAL is FATAL in debug mode, ERROR in normal mode
#ifdef NDEBUG
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__)
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::INFO, message)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, message)
#else
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::NullStream()
#if GOOGLE_STRIP_LOG <= 1
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::WARNING)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING)
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::WARNING, message)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, message)
#else
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::NullStream()
#if GOOGLE_STRIP_LOG <= 2
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::ERROR)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR)
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::ERROR, message)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, message)
#else
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::NullStream()
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::LogMessageFatal( \
__FILE__, __LINE__)
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::FATAL, message)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, message)
#else
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::NullStreamFatal()
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::FATAL)
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL)
#else
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::NullStreamFatal()
#endif
-#define GOOGLE_LOG_INFO(counter) @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::INFO, counter, &@ac_google_namespace@::LogMessage::SendToLog)
+#define GOOGLE_LOG_INFO(counter) @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, counter, &@ac_google_namespace@::LogMessage::SendToLog)
#define SYSLOG_INFO(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::INFO, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_WARNING(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::WARNING, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
#define SYSLOG_WARNING(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::WARNING, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_ERROR(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::ERROR, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
#define SYSLOG_ERROR(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::ERROR, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_FATAL(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::FATAL, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
#define SYSLOG_FATAL(counter) \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::FATAL, counter, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_DFATAL(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::DFATAL_LEVEL, counter, \
FORMAT_MESSAGE_FROM_SYSTEM, \
0, result, 0, msg, 100, NULL); \
if (message_length > 0) { \
- @ac_google_namespace@::LogMessage(__FILE__, __LINE__, ERROR, 0, \
+ @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, 0, \
&@ac_google_namespace@::LogMessage::SendToLog).stream() << message; \
LocalFree(message); \
} \
#define LOG_TO_SINK(sink, severity) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, \
- @ac_google_namespace@::severity, \
+ @ac_google_namespace@::GLOG_ ## severity, \
static_cast<@ac_google_namespace@::LogSink*>(sink), true).stream()
#define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, \
- @ac_google_namespace@::severity, \
+ @ac_google_namespace@::GLOG_ ## severity, \
static_cast<@ac_google_namespace@::LogSink*>(sink), false).stream()
// If a non-NULL string pointer is given, we write this message to that string.
#define GOOGLE_PLOG(severity, counter) \
@ac_google_namespace@::ErrnoLogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::severity, counter, \
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
#define PLOG_IF(severity, condition) \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
@ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
if (condition && \
((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
@ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
@ac_google_namespace@::ErrnoLogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) \
@ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
namespace glog_internal_namespace_ {
typedef @ac_google_namespace@::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
#define LOG_EVERY_N(severity, n) \
- GOOGLE_GLOG_COMPILE_ASSERT(@ac_google_namespace@::severity < \
+ GOOGLE_GLOG_COMPILE_ASSERT(@ac_google_namespace@::GLOG_ ## severity < \
@ac_google_namespace@::NUM_SEVERITIES, \
INVALID_REQUESTED_LOG_SEVERITY); \
SOME_KIND_OF_LOG_EVERY_N(severity, (n), @ac_google_namespace@::LogMessage::SendToLog)
// We want the special COUNTER value available for LOG_EVERY_X()'ed messages
enum PRIVATE_Counter {COUNTER};
+#ifdef GLOG_NO_ABBREVIATED_SEVERITIES
+// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
+// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
+// to keep using this syntax, we define this macro to do the same thing
+// as COMPACT_GOOGLE_LOG_ERROR.
+#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
+#define SYSLOG_0 SYSLOG_ERROR
+#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR
+// Needed for LOG_IS_ON(ERROR).
+const LogSeverity GLOG_0 = GLOG_ERROR;
+#else
+// Users may include windows.h after logging.h without
+// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
+// For this case, we cannot detect if ERROR is defined before users
+// actually use ERROR. Let's make an undefined symbol to warn users.
+# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
+# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG
+# define SYSLOG_0 GLOG_ERROR_MSG
+# define LOG_TO_STRING_0 GLOG_ERROR_MSG
+# define GLOG_0 GLOG_ERROR_MSG
+#endif
// Plus some debug-logging macros that get compiled to nothing for production
// I0821 211317 file.cc:142] RAW: status is 20
#define RAW_LOG(severity, ...) \
do { \
- switch (@ac_google_namespace@::severity) { \
+ switch (@ac_google_namespace@::GLOG_ ## severity) { \
case 0: \
RAW_LOG_INFO(__VA_ARGS__); \
break; \
#endif // STRIP_LOG == 0
#if STRIP_LOG == 0
-#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::INFO, \
+#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG == 0
#if STRIP_LOG <= 1
-#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::WARNING, \
+#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 1
#if STRIP_LOG <= 2
-#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::ERROR, \
+#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 2
#if STRIP_LOG <= 3
-#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::FATAL, \
+#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_FATAL(...) \
// The default is ERROR instead of FATAL so that users can see problems
// when they run a program without having to look in another file.
DEFINE_int32(stderrthreshold,
- GOOGLE_NAMESPACE::ERROR,
+ GOOGLE_NAMESPACE::GLOG_ERROR,
"log messages at or above this level are copied to stderr in "
"addition to logfiles. This flag obsoletes --alsologtostderr.");
LogMessage::LogMessage(const char* file, int line,
const CheckOpString& result) {
- Init(file, line, FATAL, &LogMessage::SendToLog);
+ Init(file, line, GLOG_FATAL, &LogMessage::SendToLog);
stream() << "Check failed: " << (*result.str_) << " ";
}
LogMessage::LogMessage(const char* file, int line) {
- Init(file, line, INFO, &LogMessage::SendToLog);
+ Init(file, line, GLOG_INFO, &LogMessage::SendToLog);
}
LogMessage::LogMessage(const char* file, int line, LogSeverity severity) {
LogSeverity severity,
void (LogMessage::*send_method)()) {
allocated_ = NULL;
- if (severity != FATAL || !exit_on_dfatal) {
+ if (severity != GLOG_FATAL || !exit_on_dfatal) {
allocated_ = new LogMessageData();
data_ = allocated_;
data_->buf_ = new char[kMaxLogMessageLen+1];
// Also write to stderr
WriteToStderr(fatal_message, n);
}
- LogDestination::LogToAllLogfiles(ERROR, fatal_time, fatal_message, n);
+ LogDestination::LogToAllLogfiles(GLOG_ERROR, fatal_time, fatal_message, n);
}
}
// If we log a FATAL message, flush all the log destinations, then toss
// a signal for others to catch. We leave the logs in a state that
// someone else can use them (as long as they flush afterwards)
- if (data_->severity_ == FATAL && exit_on_dfatal) {
+ if (data_->severity_ == GLOG_FATAL && exit_on_dfatal) {
if (data_->first_fatal_) {
// Store crash information so that it is accessible from within signal
// handlers that may be invoked later.
// rather scary.
// Instead just truncate the file to something we can manage
if (truncate(path, 0) == -1) {
- PLOG(ERROR) << "Unable to truncate " << path;
+ PLOG(ERROR) << "Unable to truncate " << path;
} else {
- LOG(ERROR) << "Truncated " << path << " due to EFBIG error";
+ LOG(ERROR) << "Truncated " << path << " due to EFBIG error";
}
} else {
PLOG(ERROR) << "Unable to open " << path;
}
LogMessageFatal::LogMessageFatal(const char* file, int line) :
- LogMessage(file, line, FATAL) {}
+ LogMessage(file, line, GLOG_FATAL) {}
LogMessageFatal::LogMessageFatal(const char* file, int line,
const CheckOpString& result) :
CaptureTestStderr();
// re-emit early_stderr
- LogMessage("dummy", LogMessage::kNoLogPrefix, INFO).stream() << early_stderr;
+ LogMessage("dummy", LogMessage::kNoLogPrefix, GLOG_INFO).stream() << early_stderr;
TestLogging(true);
TestRawLogging();
}
void TestLogging(bool check_counts) {
- int64 base_num_infos = LogMessage::num_messages(INFO);
- int64 base_num_warning = LogMessage::num_messages(WARNING);
- int64 base_num_errors = LogMessage::num_messages(ERROR);
+ int64 base_num_infos = LogMessage::num_messages(GLOG_INFO);
+ int64 base_num_warning = LogMessage::num_messages(GLOG_WARNING);
+ int64 base_num_errors = LogMessage::num_messages(GLOG_ERROR);
LOG(INFO) << string("foo ") << "bar " << 10 << ' ' << 3.4;
for ( int i = 0; i < 10; ++i ) {
LOG(ERROR) << string("foo") << ' '<< j << ' ' << setw(10) << j << " "
<< setw(1) << hex << j;
- LogMessage("foo", LogMessage::kNoLogPrefix, INFO).stream() << "no prefix";
+ LogMessage("foo", LogMessage::kNoLogPrefix, GLOG_INFO).stream() << "no prefix";
if (check_counts) {
- CHECK_EQ(base_num_infos + 14, LogMessage::num_messages(INFO));
- CHECK_EQ(base_num_warning + 3, LogMessage::num_messages(WARNING));
- CHECK_EQ(base_num_errors + 15, LogMessage::num_messages(ERROR));
+ CHECK_EQ(base_num_infos + 14, LogMessage::num_messages(GLOG_INFO));
+ CHECK_EQ(base_num_warning + 3, LogMessage::num_messages(GLOG_WARNING));
+ CHECK_EQ(base_num_errors + 15, LogMessage::num_messages(GLOG_ERROR));
}
}
}
void TestLoggingLevels() {
- LogWithLevels(0, INFO, false, false);
- LogWithLevels(1, INFO, false, false);
- LogWithLevels(-1, INFO, false, false);
- LogWithLevels(0, WARNING, false, false);
- LogWithLevels(0, ERROR, false, false);
- LogWithLevels(0, FATAL, false, false);
- LogWithLevels(0, FATAL, true, false);
- LogWithLevels(0, FATAL, false, true);
- LogWithLevels(1, WARNING, false, false);
- LogWithLevels(1, FATAL, false, true);
+ LogWithLevels(0, GLOG_INFO, false, false);
+ LogWithLevels(1, GLOG_INFO, false, false);
+ LogWithLevels(-1, GLOG_INFO, false, false);
+ LogWithLevels(0, GLOG_WARNING, false, false);
+ LogWithLevels(0, GLOG_ERROR, false, false);
+ LogWithLevels(0, GLOG_FATAL, false, false);
+ LogWithLevels(0, GLOG_FATAL, true, false);
+ LogWithLevels(0, GLOG_FATAL, false, true);
+ LogWithLevels(1, GLOG_WARNING, false, false);
+ LogWithLevels(1, GLOG_FATAL, false, true);
}
TEST(DeathRawCHECK, logging) {
LOG(INFO) << "Captured by LOG_TO_SINK:";
for (size_t i = 0; i < sink.errors.size(); ++i) {
- LogMessage("foo", LogMessage::kNoLogPrefix, INFO).stream()
+ LogMessage("foo", LogMessage::kNoLogPrefix, GLOG_INFO).stream()
<< sink.errors[i];
}
}
const string dest = FLAGS_test_tmpdir + "/logging_test_basename";
DeleteFiles(dest + "*");
- SetLogDestination(INFO, dest.c_str());
+ SetLogDestination(GLOG_INFO, dest.c_str());
LOG(INFO) << "message to new base";
- FlushLogFiles(INFO);
+ FlushLogFiles(GLOG_INFO);
CheckFile(dest, "message to new base");
DeleteFiles(dest + "*");
DeleteFiles(sym + "*");
- SetLogSymlink(INFO, "symlinkbase");
- SetLogDestination(INFO, dest.c_str());
+ SetLogSymlink(GLOG_INFO, "symlinkbase");
+ SetLogDestination(GLOG_INFO, dest.c_str());
LOG(INFO) << "message to new symlink";
- FlushLogFiles(INFO);
+ FlushLogFiles(GLOG_INFO);
CheckFile(sym, "message to new symlink");
DeleteFiles(dest + "*");
string dest = FLAGS_test_tmpdir + "/logging_test_extension";
DeleteFiles(dest + "*");
- SetLogDestination(INFO, dest.c_str());
+ SetLogDestination(GLOG_INFO, dest.c_str());
SetLogFilenameExtension("specialextension");
LOG(INFO) << "message to new extension";
- FlushLogFiles(INFO);
+ FlushLogFiles(GLOG_INFO);
CheckFile(dest, "message to new extension");
// Check that file name ends with extension
fprintf(stderr, "==== Test log wrapper\n");
MyLogger my_logger;
- base::Logger* old_logger = base::GetLogger(INFO);
- base::SetLogger(INFO, &my_logger);
+ base::Logger* old_logger = base::GetLogger(GLOG_INFO);
+ base::SetLogger(GLOG_INFO, &my_logger);
LOG(INFO) << "Send to wrapped logger";
- FlushLogFiles(INFO);
- base::SetLogger(INFO, old_logger);
+ FlushLogFiles(GLOG_INFO);
+ base::SetLogger(GLOG_INFO, old_logger);
CHECK(strstr(my_logger.data.c_str(), "Send to wrapped logger") != NULL);
}
// libc (to side-step any libc interception).
// We write just once to avoid races with other invocations of RawLog__.
safe_write(STDERR_FILENO, buffer, strlen(buffer));
- if (severity == FATAL) {
+ if (severity == GLOG_FATAL) {
if (!sync_val_compare_and_swap(&crashed, false, true)) {
crash_reason.filename = file;
crash_reason.line_number = line;
// you ever need to change their values or add a new severity.
typedef int LogSeverity;
-const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4;
+const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
+ NUM_SEVERITIES = 4;
+#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
+# ifdef ERROR
+# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
+# endif
+const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
+ ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
+#endif
// DFATAL is FATAL in debug mode, ERROR in normal mode
#ifdef NDEBUG
#define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \
__FILE__, __LINE__)
#define LOG_TO_STRING_INFO(message) google::LogMessage( \
- __FILE__, __LINE__, google::INFO, message)
+ __FILE__, __LINE__, google::GLOG_INFO, message)
#else
#define COMPACT_GOOGLE_LOG_INFO google::NullStream()
#define LOG_TO_STRING_INFO(message) google::NullStream()
#if GOOGLE_STRIP_LOG <= 1
#define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \
- __FILE__, __LINE__, google::WARNING)
+ __FILE__, __LINE__, google::GLOG_WARNING)
#define LOG_TO_STRING_WARNING(message) google::LogMessage( \
- __FILE__, __LINE__, google::WARNING, message)
+ __FILE__, __LINE__, google::GLOG_WARNING, message)
#else
#define COMPACT_GOOGLE_LOG_WARNING google::NullStream()
#define LOG_TO_STRING_WARNING(message) google::NullStream()
#if GOOGLE_STRIP_LOG <= 2
#define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \
- __FILE__, __LINE__, google::ERROR)
+ __FILE__, __LINE__, google::GLOG_ERROR)
#define LOG_TO_STRING_ERROR(message) google::LogMessage( \
- __FILE__, __LINE__, google::ERROR, message)
+ __FILE__, __LINE__, google::GLOG_ERROR, message)
#else
#define COMPACT_GOOGLE_LOG_ERROR google::NullStream()
#define LOG_TO_STRING_ERROR(message) google::NullStream()
#define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \
__FILE__, __LINE__)
#define LOG_TO_STRING_FATAL(message) google::LogMessage( \
- __FILE__, __LINE__, google::FATAL, message)
+ __FILE__, __LINE__, google::GLOG_FATAL, message)
#else
#define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) google::NullStreamFatal()
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \
- __FILE__, __LINE__, google::FATAL)
+ __FILE__, __LINE__, google::GLOG_FATAL)
#else
#define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal()
#endif
-#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::INFO, counter, &google::LogMessage::SendToLog)
+#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog)
#define SYSLOG_INFO(counter) \
- google::LogMessage(__FILE__, __LINE__, google::INFO, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_WARNING(counter) \
- google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_WARNING(counter) \
- google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_ERROR(counter) \
- google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_ERROR(counter) \
- google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_FATAL(counter) \
- google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_FATAL(counter) \
- google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_DFATAL(counter) \
google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
FORMAT_MESSAGE_FROM_SYSTEM, \
0, result, 0, msg, 100, NULL); \
if (message_length > 0) { \
- google::LogMessage(__FILE__, __LINE__, ERROR, 0, \
+ google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \
&google::LogMessage::SendToLog).stream() << message; \
LocalFree(message); \
} \
#define LOG_TO_SINK(sink, severity) \
google::LogMessage( \
__FILE__, __LINE__, \
- google::severity, \
+ google::GLOG_ ## severity, \
static_cast<google::LogSink*>(sink), true).stream()
#define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
google::LogMessage( \
__FILE__, __LINE__, \
- google::severity, \
+ google::GLOG_ ## severity, \
static_cast<google::LogSink*>(sink), false).stream()
// If a non-NULL string pointer is given, we write this message to that string.
#define GOOGLE_PLOG(severity, counter) \
google::ErrnoLogMessage( \
- __FILE__, __LINE__, google::severity, counter, \
+ __FILE__, __LINE__, google::GLOG_ ## severity, counter, \
&google::LogMessage::SendToLog)
#define PLOG_IF(severity, condition) \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
google::LogMessage( \
- __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
if (condition && \
((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
google::LogMessage( \
- __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
google::ErrnoLogMessage( \
- __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) \
google::LogMessage( \
- __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \
+ __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
namespace glog_internal_namespace_ {
typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
#define LOG_EVERY_N(severity, n) \
- GOOGLE_GLOG_COMPILE_ASSERT(google::severity < \
+ GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \
google::NUM_SEVERITIES, \
INVALID_REQUESTED_LOG_SEVERITY); \
SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
// We want the special COUNTER value available for LOG_EVERY_X()'ed messages
enum PRIVATE_Counter {COUNTER};
+#ifdef GLOG_NO_ABBREVIATED_SEVERITIES
+// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
+// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
+// to keep using this syntax, we define this macro to do the same thing
+// as COMPACT_GOOGLE_LOG_ERROR.
+#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
+#define SYSLOG_0 SYSLOG_ERROR
+#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR
+// Needed for LOG_IS_ON(ERROR).
+const LogSeverity GLOG_0 = GLOG_ERROR;
+#else
+// Users may include windows.h after logging.h without
+// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
+// For this case, we cannot detect if ERROR is defined before users
+// actually use ERROR. Let's make an undefined symbol to warn users.
+# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
+# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG
+# define SYSLOG_0 GLOG_ERROR_MSG
+# define LOG_TO_STRING_0 GLOG_ERROR_MSG
+# define GLOG_0 GLOG_ERROR_MSG
+#endif
// Plus some debug-logging macros that get compiled to nothing for production
// I0821 211317 file.cc:142] RAW: status is 20
#define RAW_LOG(severity, ...) \
do { \
- switch (google::severity) { \
+ switch (google::GLOG_ ## severity) { \
case 0: \
RAW_LOG_INFO(__VA_ARGS__); \
break; \
#endif // STRIP_LOG == 0
#if STRIP_LOG == 0
-#define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \
+#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG == 0
#if STRIP_LOG <= 1
-#define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING, \
+#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 1
#if STRIP_LOG <= 2
-#define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR, \
+#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 2
#if STRIP_LOG <= 3
-#define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL, \
+#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \
__FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_FATAL(...) \