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-2008 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 | #ifndef BASE_LOGGING_H_ |
michael@0 | 6 | #define BASE_LOGGING_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | #include <cstring> |
michael@0 | 10 | |
michael@0 | 11 | #include "base/basictypes.h" |
michael@0 | 12 | #include "prlog.h" |
michael@0 | 13 | |
michael@0 | 14 | #ifdef NO_CHROMIUM_LOGGING |
michael@0 | 15 | #include <sstream> |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | // Replace the Chromium logging code with NSPR-based logging code and |
michael@0 | 19 | // some C++ wrappers to emulate std::ostream |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | |
michael@0 | 23 | enum LogSeverity { |
michael@0 | 24 | LOG_INFO, |
michael@0 | 25 | LOG_WARNING, |
michael@0 | 26 | LOG_ERROR, |
michael@0 | 27 | LOG_ERROR_REPORT, |
michael@0 | 28 | LOG_FATAL, |
michael@0 | 29 | LOG_0 = LOG_ERROR |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | class Logger |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | Logger(LogSeverity severity, const char* file, int line) |
michael@0 | 36 | : mSeverity(severity) |
michael@0 | 37 | , mFile(file) |
michael@0 | 38 | , mLine(line) |
michael@0 | 39 | , mMsg(NULL) |
michael@0 | 40 | { } |
michael@0 | 41 | |
michael@0 | 42 | ~Logger(); |
michael@0 | 43 | |
michael@0 | 44 | // not private so that the operator<< overloads can get to it |
michael@0 | 45 | void printf(const char* fmt, ...); |
michael@0 | 46 | |
michael@0 | 47 | private: |
michael@0 | 48 | static PRLogModuleInfo* gChromiumPRLog; |
michael@0 | 49 | static PRLogModuleInfo* GetLog(); |
michael@0 | 50 | |
michael@0 | 51 | LogSeverity mSeverity; |
michael@0 | 52 | const char* mFile; |
michael@0 | 53 | int mLine; |
michael@0 | 54 | char* mMsg; |
michael@0 | 55 | |
michael@0 | 56 | DISALLOW_EVIL_CONSTRUCTORS(Logger); |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | class LogWrapper |
michael@0 | 60 | { |
michael@0 | 61 | public: |
michael@0 | 62 | LogWrapper(LogSeverity severity, const char* file, int line) : |
michael@0 | 63 | log(severity, file, line) { } |
michael@0 | 64 | |
michael@0 | 65 | operator Logger&() const { return log; } |
michael@0 | 66 | |
michael@0 | 67 | private: |
michael@0 | 68 | mutable Logger log; |
michael@0 | 69 | |
michael@0 | 70 | DISALLOW_EVIL_CONSTRUCTORS(LogWrapper); |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | struct EmptyLog |
michael@0 | 74 | { |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | } // namespace mozilla |
michael@0 | 78 | |
michael@0 | 79 | mozilla::Logger& operator<<(mozilla::Logger& log, const char* s); |
michael@0 | 80 | mozilla::Logger& operator<<(mozilla::Logger& log, const std::string& s); |
michael@0 | 81 | mozilla::Logger& operator<<(mozilla::Logger& log, int i); |
michael@0 | 82 | mozilla::Logger& operator<<(mozilla::Logger& log, const std::wstring& s); |
michael@0 | 83 | mozilla::Logger& operator<<(mozilla::Logger& log, void* p); |
michael@0 | 84 | |
michael@0 | 85 | template<class T> |
michael@0 | 86 | const mozilla::EmptyLog& operator <<(const mozilla::EmptyLog& log, const T&) |
michael@0 | 87 | { |
michael@0 | 88 | return log; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | #ifdef NO_CHROMIUM_LOGGING |
michael@0 | 92 | #define CHROMIUM_LOG(info) std::stringstream() |
michael@0 | 93 | #define LOG_IF(info, condition) if (!(condition)) std::stringstream() |
michael@0 | 94 | #else |
michael@0 | 95 | #define CHROMIUM_LOG(info) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__) |
michael@0 | 96 | #define LOG_IF(info, condition) \ |
michael@0 | 97 | if (!(condition)) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__) |
michael@0 | 98 | #endif |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | #ifdef DEBUG |
michael@0 | 102 | #define DLOG(info) CHROMIUM_LOG(info) |
michael@0 | 103 | #define DLOG_IF(info) LOG_IF(info) |
michael@0 | 104 | #define DCHECK(condition) CHECK(condition) |
michael@0 | 105 | #else |
michael@0 | 106 | #define DLOG(info) mozilla::EmptyLog() |
michael@0 | 107 | #define DLOG_IF(info, condition) mozilla::EmptyLog() |
michael@0 | 108 | #define DCHECK(condition) while (false && (condition)) mozilla::EmptyLog() |
michael@0 | 109 | #endif |
michael@0 | 110 | |
michael@0 | 111 | #define LOG_ASSERT(cond) CHECK(0) |
michael@0 | 112 | #define DLOG_ASSERT(cond) DCHECK(0) |
michael@0 | 113 | |
michael@0 | 114 | #define NOTREACHED() CHROMIUM_LOG(ERROR) |
michael@0 | 115 | #define NOTIMPLEMENTED() CHROMIUM_LOG(ERROR) |
michael@0 | 116 | |
michael@0 | 117 | #define CHECK(condition) LOG_IF(FATAL, condition) |
michael@0 | 118 | |
michael@0 | 119 | #define DCHECK_EQ(v1, v2) DCHECK((v1) == (v2)) |
michael@0 | 120 | #define DCHECK_NE(v1, v2) DCHECK((v1) != (v2)) |
michael@0 | 121 | #define DCHECK_LE(v1, v2) DCHECK((v1) <= (v2)) |
michael@0 | 122 | #define DCHECK_LT(v1, v2) DCHECK((v1) < (v2)) |
michael@0 | 123 | #define DCHECK_GE(v1, v2) DCHECK((v1) >= (v2)) |
michael@0 | 124 | #define DCHECK_GT(v1, v2) DCHECK((v1) > (v2)) |
michael@0 | 125 | |
michael@0 | 126 | #endif // BASE_LOGGING_H_ |