tor-browser

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

logging.h (2545B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 // Original author: ekr@rtfm.com
      8 
      9 #ifndef logging_h__
     10 #define logging_h__
     11 
     12 #include <sstream>
     13 
     14 #include "mozilla/Logging.h"
     15 
     16 #ifdef MOZILLA_INTERNAL_API
     17 
     18 #  define ML_ERROR mozilla::LogLevel::Error
     19 #  define ML_WARNING mozilla::LogLevel::Warning
     20 #  define ML_NOTICE mozilla::LogLevel::Info
     21 #  define ML_INFO mozilla::LogLevel::Debug
     22 #  define ML_DEBUG mozilla::LogLevel::Verbose
     23 
     24 #  define MOZ_MTLOG_MODULE(n)                       \
     25    static mozilla::LogModule* getLogModule() {     \
     26      static mozilla::LazyLogModule log(n);         \
     27      return static_cast<mozilla::LogModule*>(log); \
     28    }
     29 
     30 #  define MOZ_MTLOG(level, b)                                      \
     31    do {                                                           \
     32      if (MOZ_LOG_TEST(getLogModule(), level)) {                   \
     33        std::stringstream str;                                     \
     34        str << b;                                                  \
     35        MOZ_LOG(getLogModule(), level, ("%s", str.str().c_str())); \
     36      }                                                            \
     37    } while (0)
     38 #else
     39 // When building mtransport outside of XUL, for example in stand-alone gtests,
     40 // PR_Logging needs to be used instead of mozilla logging.
     41 
     42 #  include "prlog.h"
     43 
     44 #  define ML_ERROR PR_LOG_ERROR
     45 #  define ML_WARNING PR_LOG_WARNING
     46 #  define ML_NOTICE PR_LOG_INFO
     47 #  define ML_INFO PR_LOG_DEBUG
     48 #  define ML_DEBUG PR_LOG_VERBOSE
     49 
     50 #  define MOZ_MTLOG_MODULE(n)                \
     51    static PRLogModuleInfo* getLogModule() { \
     52      static PRLogModuleInfo* log;           \
     53      if (!log) log = PR_NewLogModule(n);    \
     54      return log;                            \
     55    }
     56 
     57 #  define MOZ_MTLOG(level, b)                                     \
     58    do {                                                          \
     59      if (PR_LOG_TEST(getLogModule(), level)) {                   \
     60        std::stringstream str;                                    \
     61        str << b;                                                 \
     62        PR_LOG(getLogModule(), level, ("%s", str.str().c_str())); \
     63      }                                                           \
     64    } while (0)
     65 #endif  // MOZILLA_INTERNAL_API
     66 #endif  // logging_h__