tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

logging.cc (2047B)


      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-2009 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.
      6 
      7 #include "base/logging.h"
      8 
      9 #include <utility>
     10 
     11 #include "base/string_util.h"
     12 #include "nsXPCOM.h"
     13 
     14 namespace mozilla {
     15 
     16 Logger::~Logger() {
     17  LogLevel prlevel = LogLevel::Debug;
     18  int xpcomlevel = -1;
     19 
     20  switch (mSeverity) {
     21    case LOG_INFO:
     22      prlevel = LogLevel::Debug;
     23      xpcomlevel = -1;
     24      break;
     25 
     26    case LOG_WARNING:
     27      prlevel = LogLevel::Warning;
     28      xpcomlevel = NS_DEBUG_WARNING;
     29      break;
     30 
     31    case LOG_ERROR:
     32      prlevel = LogLevel::Error;
     33      xpcomlevel = NS_DEBUG_WARNING;
     34      break;
     35 
     36    case LOG_ERROR_REPORT:
     37      prlevel = LogLevel::Error;
     38      xpcomlevel = NS_DEBUG_ASSERTION;
     39      break;
     40 
     41    case LOG_FATAL:
     42      prlevel = LogLevel::Error;
     43      xpcomlevel = NS_DEBUG_ABORT;
     44      break;
     45  }
     46 
     47  MOZ_LOG(gChromiumPRLog, prlevel,
     48          ("%s:%i: %s", mFile, mLine, mMsg ? mMsg.get() : "<no message>"));
     49  if (xpcomlevel != -1)
     50    NS_DebugBreak(xpcomlevel, mMsg.get(), NULL, mFile, mLine);
     51 }
     52 
     53 void Logger::printf(const char* fmt, ...) {
     54  va_list args;
     55  va_start(args, fmt);
     56  mMsg = mozilla::VsmprintfAppend(std::move(mMsg), fmt, args);
     57  va_end(args);
     58 }
     59 
     60 LazyLogModule Logger::gChromiumPRLog("chromium");
     61 
     62 mozilla::Logger& operator<<(mozilla::Logger& log, const char* s) {
     63  log.printf("%s", s);
     64  return log;
     65 }
     66 
     67 mozilla::Logger& operator<<(mozilla::Logger& log, const std::string& s) {
     68  log.printf("%s", s.c_str());
     69  return log;
     70 }
     71 
     72 mozilla::Logger& operator<<(mozilla::Logger& log, int i) {
     73  log.printf("%i", i);
     74  return log;
     75 }
     76 
     77 mozilla::Logger& operator<<(mozilla::Logger& log, const std::wstring& s) {
     78  log.printf("%s", WideToASCII(s).c_str());
     79  return log;
     80 }
     81 
     82 mozilla::Logger& operator<<(mozilla::Logger& log, void* p) {
     83  log.printf("%p", p);
     84  return log;
     85 }
     86 
     87 }  // namespace mozilla