DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (3bdfb7bc00a0)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_LOGGING_H_
#define BASE_LOGGING_H_

#include <string>
#include <cstring>

#include "base/basictypes.h"
#include "mozilla/Attributes.h"
#include "mozilla/Logging.h"
#include "mozilla/Printf.h"

#ifdef NO_CHROMIUM_LOGGING
#  include <sstream>
#endif

// Replace the Chromium logging code with NSPR-based logging code and
// some C++ wrappers to emulate std::ostream

namespace mozilla {

enum LogSeverity {
  LOG_INFO,
  LOG_WARNING,
  LOG_ERROR,
  LOG_ERROR_REPORT,
  LOG_FATAL,
  LOG_0 = LOG_ERROR
};

class Logger {
 public:
  Logger(LogSeverity severity, const char* file, int line)
      : mSeverity(severity), mFile(file), mLine(line) {}

  ~Logger();

  // not private so that the operator<< overloads can get to it
  void printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);

 private:
  static mozilla::LazyLogModule gChromiumPRLog;
  //  static PRLogModuleInfo* GetLog();

  LogSeverity mSeverity;
  const char* mFile;
  int mLine;
  SmprintfPointer mMsg;

  DISALLOW_EVIL_CONSTRUCTORS(Logger);
};

class LogWrapper {
 public:
  LogWrapper(LogSeverity severity, const char* file, int line)
      : log(severity, file, line) {}

  operator Logger&() const { return log; }

 private:
  mutable Logger log;

  DISALLOW_EVIL_CONSTRUCTORS(LogWrapper);
};

struct EmptyLog {};

mozilla::Logger& operator<<(mozilla::Logger& log, const char* s);
mozilla::Logger& operator<<(mozilla::Logger& log, const std::string& s);
mozilla::Logger& operator<<(mozilla::Logger& log, int i);
mozilla::Logger& operator<<(mozilla::Logger& log, const std::wstring& s);
mozilla::Logger& operator<<(mozilla::Logger& log, void* p);

template <class T>
const mozilla::EmptyLog& operator<<(const mozilla::EmptyLog& log, const T&) {
  return log;
}

}  // namespace mozilla

#ifdef NO_CHROMIUM_LOGGING
#  define CHROMIUM_LOG(info) std::stringstream()
#  define LOG_IF(info, condition) \
    if (!(condition)) std::stringstream()
#else
#  define CHROMIUM_LOG(info) \
    mozilla::LogWrapper(mozilla::LOG_##info, __FILE__, __LINE__)
#  define LOG_IF(info, condition) \
    if (!(condition))             \
    mozilla::LogWrapper(mozilla::LOG_##info, __FILE__, __LINE__)
#endif

#ifdef DEBUG
#  define DLOG(info) CHROMIUM_LOG(info)
#  define DLOG_IF(info) LOG_IF(info)
#  define DCHECK(condition) CHECK(condition)
#else
#  define DLOG(info) mozilla::EmptyLog()
#  define DLOG_IF(info, condition) mozilla::EmptyLog()
#  define DCHECK(condition) \
    while (false && (condition)) mozilla::EmptyLog()
#endif

#undef LOG_ASSERT
#define LOG_ASSERT(cond) CHECK(0)
#define DLOG_ASSERT(cond) DCHECK(0)

#define NOTREACHED() CHROMIUM_LOG(ERROR)
#define NOTIMPLEMENTED() CHROMIUM_LOG(ERROR)

#undef CHECK
#ifdef FUZZING
#  define CHECK(condition) LOG_IF(WARNING, condition)
#else
#  define CHECK(condition) LOG_IF(FATAL, condition)
#endif

#define DCHECK_EQ(v1, v2) DCHECK((v1) == (v2))
#define DCHECK_NE(v1, v2) DCHECK((v1) != (v2))
#define DCHECK_LE(v1, v2) DCHECK((v1) <= (v2))
#define DCHECK_LT(v1, v2) DCHECK((v1) < (v2))
#define DCHECK_GE(v1, v2) DCHECK((v1) >= (v2))
#define DCHECK_GT(v1, v2) DCHECK((v1) > (v2))

#endif  // BASE_LOGGING_H_