Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/re2/util/logging.h

Issue 10575037: Include RE2 library (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Less intrusive fix for Android Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/re2/util/hash.cc ('k') | third_party/re2/util/mutex.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 // Simplified version of Google's logging.
6
7 #ifndef RE2_UTIL_LOGGING_H__
8 #define RE2_UTIL_LOGGING_H__
9
10 #ifndef WIN32
11 #include <unistd.h> /* for write */
12 #endif
13 #include <sstream>
14 #ifdef WIN32
15 #include <io.h>
16 #endif
17
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))
26
27 // Always-on checking
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))
35
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
41
42 #define VLOG(x) if((x)>0){}else LOG_INFO.stream()
43
44 #ifdef NDEBUG
45 #define DEBUG_MODE 0
46 #define LOG_DFATAL LOG_ERROR
47 #else
48 #define DEBUG_MODE 1
49 #define LOG_DFATAL LOG_FATAL
50 #endif
51
52 #define LOG(severity) LOG_ ## severity.stream()
53
54 class LogMessage {
55 public:
56 LogMessage(const char* file, int line) {
57 stream() << file << ":" << line << ": ";
58 }
59 ~LogMessage() {
60 stream() << "\n";
61 string s = str_.str();
62 if(write(2, s.data(), s.size()) < 0) {} // shut up gcc
63 }
64 ostream& stream() { return str_; }
65
66 private:
67 std::ostringstream str_;
68 DISALLOW_EVIL_CONSTRUCTORS(LogMessage);
69 };
70
71 class LogMessageFatal : public LogMessage {
72 public:
73 LogMessageFatal(const char* file, int line)
74 : LogMessage(file, line) { }
75 ~LogMessageFatal() {
76 std::cerr << "\n";
77 abort();
78 }
79 private:
80 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal);
81 };
82
83 #endif // RE2_UTIL_LOGGING_H__
OLDNEW
« no previous file with comments | « third_party/re2/util/hash.cc ('k') | third_party/re2/util/mutex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698