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 | 62 int n = (int)s.size(); // shut up msvc |
63 write(2, s.data(), static_cast<unsigned int>(s.size())); | 63 if(write(2, s.data(), n) < 0) {} // shut up gcc |
64 #else | |
65 if(write(2, s.data(), s.size()) < 0) {} // shut up gcc | |
66 #endif | |
67 flushed_ = true; | 64 flushed_ = true; |
68 } | 65 } |
69 ~LogMessage() { | 66 ~LogMessage() { |
70 if (!flushed_) { | 67 if (!flushed_) { |
71 Flush(); | 68 Flush(); |
72 } | 69 } |
73 } | 70 } |
74 ostream& stream() { return str_; } | 71 ostream& stream() { return str_; } |
75 | 72 |
76 private: | 73 private: |
77 bool flushed_; | 74 bool flushed_; |
78 std::ostringstream str_; | 75 std::ostringstream str_; |
79 DISALLOW_EVIL_CONSTRUCTORS(LogMessage); | 76 DISALLOW_EVIL_CONSTRUCTORS(LogMessage); |
80 }; | 77 }; |
81 | 78 |
82 class LogMessageFatal : public LogMessage { | 79 class LogMessageFatal : public LogMessage { |
83 public: | 80 public: |
84 LogMessageFatal(const char* file, int line) | 81 LogMessageFatal(const char* file, int line) |
85 : LogMessage(file, line) { } | 82 : LogMessage(file, line) { } |
86 ~LogMessageFatal() { | 83 ~LogMessageFatal() { |
87 Flush(); | 84 Flush(); |
88 abort(); | 85 abort(); |
89 } | 86 } |
90 private: | 87 private: |
91 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal); | 88 DISALLOW_EVIL_CONSTRUCTORS(LogMessageFatal); |
92 }; | 89 }; |
93 | 90 |
94 #endif // RE2_UTIL_LOGGING_H__ | 91 #endif // RE2_UTIL_LOGGING_H__ |
OLD | NEW |