OLD | NEW |
---|---|
1 // Copyright 2009 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2009 The RE2 Authors. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Simplified version of Google's logging. | 5 // Simplified version of Google's logging. |
6 | 6 |
7 #ifndef RE2_UTIL_LOGGING_H__ | 7 #ifndef RE2_UTIL_LOGGING_H__ |
8 #define RE2_UTIL_LOGGING_H__ | 8 #define RE2_UTIL_LOGGING_H__ |
9 | 9 |
10 #ifndef WIN32 | 10 #ifndef WIN32 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #define LOG(severity) LOG_ ## severity.stream() | 52 #define LOG(severity) LOG_ ## severity.stream() |
53 | 53 |
54 class LogMessage { | 54 class LogMessage { |
55 public: | 55 public: |
56 LogMessage(const char* file, int line) : flushed_(false) { | 56 LogMessage(const char* file, int line) : flushed_(false) { |
57 stream() << file << ":" << line << ": "; | 57 stream() << file << ":" << line << ": "; |
58 } | 58 } |
59 void Flush() { | 59 void Flush() { |
60 stream() << "\n"; | 60 stream() << "\n"; |
61 string s = str_.str(); | 61 string s = str_.str(); |
62 #ifdef WIN32 | |
63 write(2, s.data(), static_cast<unsigned int>(s.size())); | |
scottmg
2013/01/09 22:28:34
io.h's write only takes unsigned int.
| |
64 #else | |
62 if(write(2, s.data(), s.size()) < 0) {} // shut up gcc | 65 if(write(2, s.data(), s.size()) < 0) {} // shut up gcc |
66 #endif | |
63 flushed_ = true; | 67 flushed_ = true; |
64 } | 68 } |
65 ~LogMessage() { | 69 ~LogMessage() { |
66 if (!flushed_) { | 70 if (!flushed_) { |
67 Flush(); | 71 Flush(); |
68 } | 72 } |
69 } | 73 } |
70 ostream& stream() { return str_; } | 74 ostream& stream() { return str_; } |
71 | 75 |
72 private: | 76 private: |
73 bool flushed_; | 77 bool flushed_; |
74 std::ostringstream str_; | 78 std::ostringstream str_; |
75 DISALLOW_EVIL_CONSTRUCTORS(LogMessage); | 79 DISALLOW_EVIL_CONSTRUCTORS(LogMessage); |
76 }; | 80 }; |
77 | 81 |
78 class LogMessageFatal : public LogMessage { | 82 class LogMessageFatal : public LogMessage { |
79 public: | 83 public: |
80 LogMessageFatal(const char* file, int line) | 84 LogMessageFatal(const char* file, int line) |
81 : LogMessage(file, line) { } | 85 : LogMessage(file, line) { } |
82 ~LogMessageFatal() { | 86 ~LogMessageFatal() { |
83 Flush(); | 87 Flush(); |
84 abort(); | 88 abort(); |
85 } | 89 } |
86 private: | 90 private: |
87 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal); | 91 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal); |
88 }; | 92 }; |
89 | 93 |
90 #endif // RE2_UTIL_LOGGING_H__ | 94 #endif // RE2_UTIL_LOGGING_H__ |
OLD | NEW |