1 // Copyright 2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Simplified version of Google's logging.
7 #ifndef RE2_UTIL_LOGGING_H__
8 #define RE2_UTIL_LOGGING_H__
11 #include <unistd.h> /* for write */
18 // Debug-only checking.
19 #define DCHECK(condition) assert(condition)
20 #define DCHECK_EQ(val1, val2) assert((val1) == (val2))
21 #define DCHECK_NE(val1, val2) assert((val1) != (val2))
22 #define DCHECK_LE(val1, val2) assert((val1) <= (val2))
23 #define DCHECK_LT(val1, val2) assert((val1) < (val2))
24 #define DCHECK_GE(val1, val2) assert((val1) >= (val2))
25 #define DCHECK_GT(val1, val2) assert((val1) > (val2))
28 #define CHECK(x) if(x){}else LogMessageFatal(__FILE__, __LINE__).stream() << "Check failed: " #x
29 #define CHECK_LT(x, y) CHECK((x) < (y))
30 #define CHECK_GT(x, y) CHECK((x) > (y))
31 #define CHECK_LE(x, y) CHECK((x) <= (y))
32 #define CHECK_GE(x, y) CHECK((x) >= (y))
33 #define CHECK_EQ(x, y) CHECK((x) == (y))
34 #define CHECK_NE(x, y) CHECK((x) != (y))
36 #define LOG_INFO LogMessage(__FILE__, __LINE__)
37 #define LOG_ERROR LOG_INFO
38 #define LOG_WARNING LOG_INFO
39 #define LOG_FATAL LogMessageFatal(__FILE__, __LINE__)
40 #define LOG_QFATAL LOG_FATAL
42 #define VLOG(x) if((x)>0){}else LOG_INFO.stream()
46 #define LOG_DFATAL LOG_ERROR
49 #define LOG_DFATAL LOG_FATAL
52 #define LOG(severity) LOG_ ## severity.stream()
56 LogMessage(const char* file
, int line
) : flushed_(false) {
57 stream() << file
<< ":" << line
<< ": ";
61 string s
= str_
.str();
62 int n
= (int)s
.size(); // shut up msvc
63 if(write(2, s
.data(), n
) < 0) {} // shut up gcc
71 ostream
& stream() { return str_
; }
75 std::ostringstream str_
;
76 DISALLOW_EVIL_CONSTRUCTORS(LogMessage
);
79 class LogMessageFatal
: public LogMessage
{
81 LogMessageFatal(const char* file
, int line
)
82 : LogMessage(file
, line
) { }
88 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal
);
91 #endif // RE2_UTIL_LOGGING_H__