Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/logging.h" |
michael@0 | 6 | #include "prmem.h" |
michael@0 | 7 | #include "prprf.h" |
michael@0 | 8 | #include "base/string_util.h" |
michael@0 | 9 | #include "nsXPCOM.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | Logger::~Logger() |
michael@0 | 14 | { |
michael@0 | 15 | PRLogModuleLevel prlevel = PR_LOG_DEBUG; |
michael@0 | 16 | int xpcomlevel = -1; |
michael@0 | 17 | |
michael@0 | 18 | switch (mSeverity) { |
michael@0 | 19 | case LOG_INFO: |
michael@0 | 20 | prlevel = PR_LOG_DEBUG; |
michael@0 | 21 | xpcomlevel = -1; |
michael@0 | 22 | break; |
michael@0 | 23 | |
michael@0 | 24 | case LOG_WARNING: |
michael@0 | 25 | prlevel = PR_LOG_WARNING; |
michael@0 | 26 | xpcomlevel = NS_DEBUG_WARNING; |
michael@0 | 27 | break; |
michael@0 | 28 | |
michael@0 | 29 | case LOG_ERROR: |
michael@0 | 30 | prlevel = PR_LOG_ERROR; |
michael@0 | 31 | xpcomlevel = NS_DEBUG_WARNING; |
michael@0 | 32 | break; |
michael@0 | 33 | |
michael@0 | 34 | case LOG_ERROR_REPORT: |
michael@0 | 35 | prlevel = PR_LOG_ERROR; |
michael@0 | 36 | xpcomlevel = NS_DEBUG_ASSERTION; |
michael@0 | 37 | break; |
michael@0 | 38 | |
michael@0 | 39 | case LOG_FATAL: |
michael@0 | 40 | prlevel = PR_LOG_ERROR; |
michael@0 | 41 | xpcomlevel = NS_DEBUG_ABORT; |
michael@0 | 42 | break; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | PR_LOG(GetLog(), prlevel, ("%s:%i: %s", mFile, mLine, mMsg ? mMsg : "<no message>")); |
michael@0 | 46 | if (xpcomlevel != -1) |
michael@0 | 47 | NS_DebugBreak(xpcomlevel, mMsg, NULL, mFile, mLine); |
michael@0 | 48 | |
michael@0 | 49 | PR_Free(mMsg); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | void |
michael@0 | 53 | Logger::printf(const char* fmt, ...) |
michael@0 | 54 | { |
michael@0 | 55 | va_list args; |
michael@0 | 56 | va_start(args, fmt); |
michael@0 | 57 | mMsg = PR_vsprintf_append(mMsg, fmt, args); |
michael@0 | 58 | va_end(args); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | PRLogModuleInfo* Logger::gChromiumPRLog; |
michael@0 | 62 | |
michael@0 | 63 | PRLogModuleInfo* Logger::GetLog() |
michael@0 | 64 | { |
michael@0 | 65 | if (!gChromiumPRLog) |
michael@0 | 66 | gChromiumPRLog = PR_NewLogModule("chromium"); |
michael@0 | 67 | return gChromiumPRLog; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | } // namespace mozilla |
michael@0 | 71 | |
michael@0 | 72 | mozilla::Logger& |
michael@0 | 73 | operator<<(mozilla::Logger& log, const char* s) |
michael@0 | 74 | { |
michael@0 | 75 | log.printf("%s", s); |
michael@0 | 76 | return log; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | mozilla::Logger& |
michael@0 | 80 | operator<<(mozilla::Logger& log, const std::string& s) |
michael@0 | 81 | { |
michael@0 | 82 | log.printf("%s", s.c_str()); |
michael@0 | 83 | return log; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | mozilla::Logger& |
michael@0 | 87 | operator<<(mozilla::Logger& log, int i) |
michael@0 | 88 | { |
michael@0 | 89 | log.printf("%i", i); |
michael@0 | 90 | return log; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | mozilla::Logger& |
michael@0 | 94 | operator<<(mozilla::Logger& log, const std::wstring& s) |
michael@0 | 95 | { |
michael@0 | 96 | log.printf("%s", WideToASCII(s).c_str()); |
michael@0 | 97 | return log; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | mozilla::Logger& |
michael@0 | 101 | operator<<(mozilla::Logger& log, void* p) |
michael@0 | 102 | { |
michael@0 | 103 | log.printf("%p", p); |
michael@0 | 104 | return log; |
michael@0 | 105 | } |