michael@0: // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/logging.h" michael@0: #include "prmem.h" michael@0: #include "prprf.h" michael@0: #include "base/string_util.h" michael@0: #include "nsXPCOM.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: Logger::~Logger() michael@0: { michael@0: PRLogModuleLevel prlevel = PR_LOG_DEBUG; michael@0: int xpcomlevel = -1; michael@0: michael@0: switch (mSeverity) { michael@0: case LOG_INFO: michael@0: prlevel = PR_LOG_DEBUG; michael@0: xpcomlevel = -1; michael@0: break; michael@0: michael@0: case LOG_WARNING: michael@0: prlevel = PR_LOG_WARNING; michael@0: xpcomlevel = NS_DEBUG_WARNING; michael@0: break; michael@0: michael@0: case LOG_ERROR: michael@0: prlevel = PR_LOG_ERROR; michael@0: xpcomlevel = NS_DEBUG_WARNING; michael@0: break; michael@0: michael@0: case LOG_ERROR_REPORT: michael@0: prlevel = PR_LOG_ERROR; michael@0: xpcomlevel = NS_DEBUG_ASSERTION; michael@0: break; michael@0: michael@0: case LOG_FATAL: michael@0: prlevel = PR_LOG_ERROR; michael@0: xpcomlevel = NS_DEBUG_ABORT; michael@0: break; michael@0: } michael@0: michael@0: PR_LOG(GetLog(), prlevel, ("%s:%i: %s", mFile, mLine, mMsg ? mMsg : "")); michael@0: if (xpcomlevel != -1) michael@0: NS_DebugBreak(xpcomlevel, mMsg, NULL, mFile, mLine); michael@0: michael@0: PR_Free(mMsg); michael@0: } michael@0: michael@0: void michael@0: Logger::printf(const char* fmt, ...) michael@0: { michael@0: va_list args; michael@0: va_start(args, fmt); michael@0: mMsg = PR_vsprintf_append(mMsg, fmt, args); michael@0: va_end(args); michael@0: } michael@0: michael@0: PRLogModuleInfo* Logger::gChromiumPRLog; michael@0: michael@0: PRLogModuleInfo* Logger::GetLog() michael@0: { michael@0: if (!gChromiumPRLog) michael@0: gChromiumPRLog = PR_NewLogModule("chromium"); michael@0: return gChromiumPRLog; michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: michael@0: mozilla::Logger& michael@0: operator<<(mozilla::Logger& log, const char* s) michael@0: { michael@0: log.printf("%s", s); michael@0: return log; michael@0: } michael@0: michael@0: mozilla::Logger& michael@0: operator<<(mozilla::Logger& log, const std::string& s) michael@0: { michael@0: log.printf("%s", s.c_str()); michael@0: return log; michael@0: } michael@0: michael@0: mozilla::Logger& michael@0: operator<<(mozilla::Logger& log, int i) michael@0: { michael@0: log.printf("%i", i); michael@0: return log; michael@0: } michael@0: michael@0: mozilla::Logger& michael@0: operator<<(mozilla::Logger& log, const std::wstring& s) michael@0: { michael@0: log.printf("%s", WideToASCII(s).c_str()); michael@0: return log; michael@0: } michael@0: michael@0: mozilla::Logger& michael@0: operator<<(mozilla::Logger& log, void* p) michael@0: { michael@0: log.printf("%p", p); michael@0: return log; michael@0: }