aboutsummaryrefslogtreecommitdiff
path: root/util/logging.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/logging.h')
-rw-r--r--util/logging.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/util/logging.h b/util/logging.h
index c8f6604..4443f7c 100644
--- a/util/logging.h
+++ b/util/logging.h
@@ -48,17 +48,25 @@
class LogMessage {
public:
- LogMessage(const char* file, int line) {
+ LogMessage(const char* file, int line) : flushed_(false) {
stream() << file << ":" << line << ": ";
}
- ~LogMessage() {
+ void Flush() {
stream() << "\n";
string s = str_.str();
- if(write(2, s.data(), s.size()) < 0) {} // shut up gcc
+ int n = (int)s.size(); // shut up msvc
+ if(write(2, s.data(), n) < 0) {} // shut up gcc
+ flushed_ = true;
+ }
+ ~LogMessage() {
+ if (!flushed_) {
+ Flush();
+ }
}
ostream& stream() { return str_; }
private:
+ bool flushed_;
std::ostringstream str_;
DISALLOW_EVIL_CONSTRUCTORS(LogMessage);
};
@@ -68,7 +76,7 @@ class LogMessageFatal : public LogMessage {
LogMessageFatal(const char* file, int line)
: LogMessage(file, line) { }
~LogMessageFatal() {
- std::cerr << "\n";
+ Flush();
abort();
}
private: