ipc/chromium/src/base/logging.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #ifndef BASE_LOGGING_H_
     6 #define BASE_LOGGING_H_
     8 #include <string>
     9 #include <cstring>
    11 #include "base/basictypes.h"
    12 #include "prlog.h"
    14 #ifdef NO_CHROMIUM_LOGGING
    15 #include <sstream>
    16 #endif
    18 // Replace the Chromium logging code with NSPR-based logging code and
    19 // some C++ wrappers to emulate std::ostream
    21 namespace mozilla {
    23 enum LogSeverity {
    24   LOG_INFO,
    25   LOG_WARNING,
    26   LOG_ERROR,
    27   LOG_ERROR_REPORT,
    28   LOG_FATAL,
    29   LOG_0 = LOG_ERROR
    30 };
    32 class Logger
    33 {
    34 public:
    35   Logger(LogSeverity severity, const char* file, int line)
    36     : mSeverity(severity)
    37     , mFile(file)
    38     , mLine(line)
    39     , mMsg(NULL)
    40   { }
    42   ~Logger();
    44   // not private so that the operator<< overloads can get to it
    45   void printf(const char* fmt, ...);
    47 private:
    48   static PRLogModuleInfo* gChromiumPRLog;
    49   static PRLogModuleInfo* GetLog();
    51   LogSeverity mSeverity;
    52   const char* mFile;
    53   int mLine;
    54   char* mMsg;
    56   DISALLOW_EVIL_CONSTRUCTORS(Logger);
    57 };
    59 class LogWrapper
    60 {
    61 public:
    62   LogWrapper(LogSeverity severity, const char* file, int line) :
    63     log(severity, file, line) { }
    65   operator Logger&() const { return log; }
    67 private:
    68   mutable Logger log;
    70   DISALLOW_EVIL_CONSTRUCTORS(LogWrapper);
    71 };
    73 struct EmptyLog
    74 {
    75 };
    77 } // namespace mozilla
    79 mozilla::Logger& operator<<(mozilla::Logger& log, const char* s);
    80 mozilla::Logger& operator<<(mozilla::Logger& log, const std::string& s);
    81 mozilla::Logger& operator<<(mozilla::Logger& log, int i);
    82 mozilla::Logger& operator<<(mozilla::Logger& log, const std::wstring& s);
    83 mozilla::Logger& operator<<(mozilla::Logger& log, void* p);
    85 template<class T>
    86 const mozilla::EmptyLog& operator <<(const mozilla::EmptyLog& log, const T&)
    87 {
    88   return log;
    89 }
    91 #ifdef NO_CHROMIUM_LOGGING
    92 #define CHROMIUM_LOG(info) std::stringstream()
    93 #define LOG_IF(info, condition) if (!(condition)) std::stringstream()
    94 #else
    95 #define CHROMIUM_LOG(info) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__)
    96 #define LOG_IF(info, condition) \
    97   if (!(condition)) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__)
    98 #endif
   101 #ifdef DEBUG
   102 #define DLOG(info) CHROMIUM_LOG(info)
   103 #define DLOG_IF(info) LOG_IF(info)
   104 #define DCHECK(condition) CHECK(condition)
   105 #else
   106 #define DLOG(info) mozilla::EmptyLog()
   107 #define DLOG_IF(info, condition) mozilla::EmptyLog()
   108 #define DCHECK(condition) while (false && (condition)) mozilla::EmptyLog()
   109 #endif
   111 #define LOG_ASSERT(cond) CHECK(0)
   112 #define DLOG_ASSERT(cond) DCHECK(0)
   114 #define NOTREACHED() CHROMIUM_LOG(ERROR)
   115 #define NOTIMPLEMENTED() CHROMIUM_LOG(ERROR)
   117 #define CHECK(condition) LOG_IF(FATAL, condition)
   119 #define DCHECK_EQ(v1, v2) DCHECK((v1) == (v2))
   120 #define DCHECK_NE(v1, v2) DCHECK((v1) != (v2))
   121 #define DCHECK_LE(v1, v2) DCHECK((v1) <= (v2))
   122 #define DCHECK_LT(v1, v2) DCHECK((v1) < (v2))
   123 #define DCHECK_GE(v1, v2) DCHECK((v1) >= (v2))
   124 #define DCHECK_GT(v1, v2) DCHECK((v1) > (v2))
   126 #endif  // BASE_LOGGING_H_

mercurial