diff options
-rw-r--r-- | base/logging.cc | 9 | ||||
-rw-r--r-- | base/logging.h | 19 |
2 files changed, 28 insertions, 0 deletions
diff --git a/base/logging.cc b/base/logging.cc index 41a0933..961ea6c 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -342,6 +342,15 @@ void DisplayDebugMessage(const std::string& str) { #endif } +#if defined(OS_WIN) +LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) { +} + +LogMessage::SaveLastError::~SaveLastError() { + ::SetLastError(last_error_); +} +#endif // defined(OS_WIN) + LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int ctr) : severity_(severity) { diff --git a/base/logging.h b/base/logging.h index b3bba0b..6a58cf3 100644 --- a/base/logging.h +++ b/base/logging.h @@ -540,6 +540,25 @@ class LogMessage { std::ostringstream stream_; size_t message_start_; // Offset of the start of the message (past prefix // info). +#if defined(OS_WIN) + // Stores the current value of GetLastError in the constructor and restores + // it in the destructor by calling SetLastError. + // This is useful since the LogMessage class uses a lot of Win32 calls + // that will lose the value of GLE and the code that called the log function + // will have lost the thread error value when the log call returns. + class SaveLastError { + public: + SaveLastError(); + ~SaveLastError(); + + unsigned long get_error() const { return last_error_; } + + protected: + unsigned long last_error_; + }; + + SaveLastError last_error_; +#endif DISALLOW_COPY_AND_ASSIGN(LogMessage); }; |