1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
7 #ifndef BASE_LOGGING_H_
8 #define BASE_LOGGING_H_
13 #include "base/basictypes.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Logging.h"
16 #include "mozilla/Printf.h"
18 #ifdef NO_CHROMIUM_LOGGING
22 // Replace the Chromium logging code with NSPR-based logging code and
23 // some C++ wrappers to emulate std::ostream
38 Logger(LogSeverity severity
, const char* file
, int line
)
39 : mSeverity(severity
), mFile(file
), mLine(line
) {}
43 // not private so that the operator<< overloads can get to it
44 void printf(const char* fmt
, ...) MOZ_FORMAT_PRINTF(2, 3);
47 static mozilla::LazyLogModule gChromiumPRLog
;
48 // static PRLogModuleInfo* GetLog();
50 LogSeverity mSeverity
;
55 DISALLOW_EVIL_CONSTRUCTORS(Logger
);
60 LogWrapper(LogSeverity severity
, const char* file
, int line
)
61 : log(severity
, file
, line
) {}
63 operator Logger
&() const { return log
; }
68 DISALLOW_EVIL_CONSTRUCTORS(LogWrapper
);
73 mozilla::Logger
& operator<<(mozilla::Logger
& log
, const char* s
);
74 mozilla::Logger
& operator<<(mozilla::Logger
& log
, const std::string
& s
);
75 mozilla::Logger
& operator<<(mozilla::Logger
& log
, int i
);
76 mozilla::Logger
& operator<<(mozilla::Logger
& log
, const std::wstring
& s
);
77 mozilla::Logger
& operator<<(mozilla::Logger
& log
, void* p
);
80 const mozilla::EmptyLog
& operator<<(const mozilla::EmptyLog
& log
, const T
&) {
84 } // namespace mozilla
86 #ifdef NO_CHROMIUM_LOGGING
87 # define CHROMIUM_LOG(info) std::stringstream()
88 # define LOG_IF(info, condition) \
89 if (!(condition)) std::stringstream()
91 # define CHROMIUM_LOG(info) \
92 mozilla::LogWrapper(mozilla::LOG_##info, __FILE__, __LINE__)
93 # define LOG_IF(info, condition) \
95 mozilla::LogWrapper(mozilla::LOG_##info, __FILE__, __LINE__)
99 # define DLOG(info) CHROMIUM_LOG(info)
100 # define DLOG_IF(info, condition) LOG_IF(info, condition)
101 # define DCHECK(condition) CHECK(condition)
103 # define DLOG(info) mozilla::EmptyLog()
104 # define DLOG_IF(info, condition) mozilla::EmptyLog()
105 # define DCHECK(condition) \
106 while (false && (condition)) mozilla::EmptyLog()
109 #define DVLOG(level) DLOG(INFO)
112 #define LOG_ASSERT(cond) CHECK(0)
113 #define DLOG_ASSERT(cond) DCHECK(0)
115 #define NOTREACHED() CHROMIUM_LOG(ERROR)
116 #define NOTIMPLEMENTED() CHROMIUM_LOG(ERROR)
120 # define CHECK(condition) LOG_IF(WARNING, condition)
122 # define CHECK(condition) LOG_IF(FATAL, condition)
125 #define DCHECK_EQ(v1, v2) DCHECK((v1) == (v2))
126 #define DCHECK_NE(v1, v2) DCHECK((v1) != (v2))
127 #define DCHECK_LE(v1, v2) DCHECK((v1) <= (v2))
128 #define DCHECK_LT(v1, v2) DCHECK((v1) < (v2))
129 #define DCHECK_GE(v1, v2) DCHECK((v1) >= (v2))
130 #define DCHECK_GT(v1, v2) DCHECK((v1) > (v2))
132 #endif // BASE_LOGGING_H_