ipc/chromium/src/base/logging.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/logging.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_LOGGING_H_
     1.9 +#define BASE_LOGGING_H_
    1.10 +
    1.11 +#include <string>
    1.12 +#include <cstring>
    1.13 +
    1.14 +#include "base/basictypes.h"
    1.15 +#include "prlog.h"
    1.16 +
    1.17 +#ifdef NO_CHROMIUM_LOGGING
    1.18 +#include <sstream>
    1.19 +#endif
    1.20 +
    1.21 +// Replace the Chromium logging code with NSPR-based logging code and
    1.22 +// some C++ wrappers to emulate std::ostream
    1.23 +
    1.24 +namespace mozilla {
    1.25 +
    1.26 +enum LogSeverity {
    1.27 +  LOG_INFO,
    1.28 +  LOG_WARNING,
    1.29 +  LOG_ERROR,
    1.30 +  LOG_ERROR_REPORT,
    1.31 +  LOG_FATAL,
    1.32 +  LOG_0 = LOG_ERROR
    1.33 +};
    1.34 +
    1.35 +class Logger
    1.36 +{
    1.37 +public:
    1.38 +  Logger(LogSeverity severity, const char* file, int line)
    1.39 +    : mSeverity(severity)
    1.40 +    , mFile(file)
    1.41 +    , mLine(line)
    1.42 +    , mMsg(NULL)
    1.43 +  { }
    1.44 +
    1.45 +  ~Logger();
    1.46 +
    1.47 +  // not private so that the operator<< overloads can get to it
    1.48 +  void printf(const char* fmt, ...);
    1.49 +
    1.50 +private:
    1.51 +  static PRLogModuleInfo* gChromiumPRLog;
    1.52 +  static PRLogModuleInfo* GetLog();
    1.53 +
    1.54 +  LogSeverity mSeverity;
    1.55 +  const char* mFile;
    1.56 +  int mLine;
    1.57 +  char* mMsg;
    1.58 +
    1.59 +  DISALLOW_EVIL_CONSTRUCTORS(Logger);
    1.60 +};
    1.61 +
    1.62 +class LogWrapper
    1.63 +{
    1.64 +public:
    1.65 +  LogWrapper(LogSeverity severity, const char* file, int line) :
    1.66 +    log(severity, file, line) { }
    1.67 +
    1.68 +  operator Logger&() const { return log; }
    1.69 +
    1.70 +private:
    1.71 +  mutable Logger log;
    1.72 +
    1.73 +  DISALLOW_EVIL_CONSTRUCTORS(LogWrapper);
    1.74 +};
    1.75 +
    1.76 +struct EmptyLog
    1.77 +{
    1.78 +};
    1.79 +
    1.80 +} // namespace mozilla
    1.81 +
    1.82 +mozilla::Logger& operator<<(mozilla::Logger& log, const char* s);
    1.83 +mozilla::Logger& operator<<(mozilla::Logger& log, const std::string& s);
    1.84 +mozilla::Logger& operator<<(mozilla::Logger& log, int i);
    1.85 +mozilla::Logger& operator<<(mozilla::Logger& log, const std::wstring& s);
    1.86 +mozilla::Logger& operator<<(mozilla::Logger& log, void* p);
    1.87 +
    1.88 +template<class T>
    1.89 +const mozilla::EmptyLog& operator <<(const mozilla::EmptyLog& log, const T&)
    1.90 +{
    1.91 +  return log;
    1.92 +}
    1.93 +
    1.94 +#ifdef NO_CHROMIUM_LOGGING
    1.95 +#define CHROMIUM_LOG(info) std::stringstream()
    1.96 +#define LOG_IF(info, condition) if (!(condition)) std::stringstream()
    1.97 +#else
    1.98 +#define CHROMIUM_LOG(info) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__)
    1.99 +#define LOG_IF(info, condition) \
   1.100 +  if (!(condition)) mozilla::LogWrapper(mozilla::LOG_ ## info, __FILE__, __LINE__)
   1.101 +#endif
   1.102 +
   1.103 +
   1.104 +#ifdef DEBUG
   1.105 +#define DLOG(info) CHROMIUM_LOG(info)
   1.106 +#define DLOG_IF(info) LOG_IF(info)
   1.107 +#define DCHECK(condition) CHECK(condition)
   1.108 +#else
   1.109 +#define DLOG(info) mozilla::EmptyLog()
   1.110 +#define DLOG_IF(info, condition) mozilla::EmptyLog()
   1.111 +#define DCHECK(condition) while (false && (condition)) mozilla::EmptyLog()
   1.112 +#endif
   1.113 +
   1.114 +#define LOG_ASSERT(cond) CHECK(0)
   1.115 +#define DLOG_ASSERT(cond) DCHECK(0)
   1.116 +
   1.117 +#define NOTREACHED() CHROMIUM_LOG(ERROR)
   1.118 +#define NOTIMPLEMENTED() CHROMIUM_LOG(ERROR)
   1.119 +
   1.120 +#define CHECK(condition) LOG_IF(FATAL, condition)
   1.121 +
   1.122 +#define DCHECK_EQ(v1, v2) DCHECK((v1) == (v2))
   1.123 +#define DCHECK_NE(v1, v2) DCHECK((v1) != (v2))
   1.124 +#define DCHECK_LE(v1, v2) DCHECK((v1) <= (v2))
   1.125 +#define DCHECK_LT(v1, v2) DCHECK((v1) < (v2))
   1.126 +#define DCHECK_GE(v1, v2) DCHECK((v1) >= (v2))
   1.127 +#define DCHECK_GT(v1, v2) DCHECK((v1) > (v2))
   1.128 +
   1.129 +#endif  // BASE_LOGGING_H_

mercurial