From 2962b23886e9b922398b573fadfa7993f1cb26d7 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 16 Sep 2009 06:59:17 +0000 Subject: Simplifies the implementation of GTEST_LOG_ & GTEST_LOG_; renames GTEST_HIDE_UNREACHABLE_CODE_ to GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ (by Vlad Losev). git-svn-id: http://googletest.googlecode.com/svn/trunk@307 861a406c-534a-0410-8894-cb66d6ee9925 --- src/gtest-port.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gtest-port.cc') diff --git a/src/gtest-port.cc b/src/gtest-port.cc index ec107a5..ba9a9a2 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -417,20 +417,25 @@ void RE::Init(const char* regex) { #endif // GTEST_USES_POSIX_RE -// Logs a message at the given severity level. -void GTestLog(GTestLogSeverity severity, const char* file, - int line, const char* msg) { + +GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line) + : severity_(severity) { const char* const marker = severity == GTEST_INFO ? "[ INFO ]" : severity == GTEST_WARNING ? "[WARNING]" : severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]"; - fprintf(stderr, "\n%s %s:%d: %s\n", marker, file, line, msg); - if (severity == GTEST_FATAL) { - fflush(NULL); // abort() is not guaranteed to flush open file streams. + GetStream() << ::std::endl << marker << " " + << FormatFileLocation(file, line).c_str() << ": "; +} + +// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. +GTestLog::~GTestLog() { + GetStream() << ::std::endl; + if (severity_ == GTEST_FATAL) { + fflush(stderr); posix::Abort(); } } - // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) #ifdef _MSC_VER @@ -537,7 +542,7 @@ static String ReadEntireFile(FILE * file) { // Starts capturing stderr. void CaptureStderr() { if (g_captured_stderr != NULL) { - GTEST_LOG_(FATAL, "Only one stderr capturer can exist at one time."); + GTEST_LOG_(FATAL) << "Only one stderr capturer can exist at one time."; } g_captured_stderr = new CapturedStderr; } -- cgit v1.2.3