tor-browser

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

SdpLog.cpp (2196B)


      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 #include "sdp/SdpLog.h"
      7 
      8 #include <type_traits>
      9 
     10 #include "common/browser_logging/CSFLog.h"
     11 
     12 namespace mozilla {
     13 LazyLogModule SdpLog("sdp");
     14 }  // namespace mozilla
     15 
     16 // For compile time enum comparison
     17 template <typename E, typename F>
     18 constexpr bool compareEnum(E e, F f) {
     19  return static_cast<typename std::underlying_type<E>::type>(e) ==
     20         static_cast<typename std::underlying_type<F>::type>(f);
     21 }
     22 
     23 CSFLogLevel SDPToCSFLogLevel(const SDPLogLevel priority) {
     24  static_assert(compareEnum(SDP_LOG_ERROR, CSF_LOG_ERROR));
     25  static_assert(compareEnum(SDP_LOG_WARNING, CSF_LOG_WARNING));
     26  static_assert(compareEnum(SDP_LOG_INFO, CSF_LOG_INFO));
     27  static_assert(compareEnum(SDP_LOG_DEBUG, CSF_LOG_DEBUG));
     28  static_assert(compareEnum(SDP_LOG_VERBOSE, CSF_LOG_VERBOSE));
     29 
     30  // Check that all SDP_LOG_* cases are covered. It compiles to nothing.
     31  switch (priority) {
     32    case SDP_LOG_ERROR:
     33    case SDP_LOG_WARNING:
     34    case SDP_LOG_INFO:
     35    case SDP_LOG_DEBUG:
     36    case SDP_LOG_VERBOSE:
     37      break;
     38  }
     39 
     40  // Ditto for CSF_LOG_*
     41  switch (static_cast<CSFLogLevel>(priority)) {
     42    case CSF_LOG_ERROR:
     43    case CSF_LOG_WARNING:
     44    case CSF_LOG_INFO:
     45    case CSF_LOG_DEBUG:
     46    case CSF_LOG_VERBOSE:
     47      break;
     48  }
     49 
     50  return static_cast<CSFLogLevel>(priority);
     51 }
     52 
     53 void SDPLog(SDPLogLevel priority, const char* sourceFile, int sourceLine,
     54            const char* tag, const char* format, ...) {
     55  va_list ap;
     56  va_start(ap, format);
     57  CSFLogV(SDPToCSFLogLevel(priority), sourceFile, sourceLine, tag, format, ap);
     58  va_end(ap);
     59 }
     60 
     61 void SDPLogV(SDPLogLevel priority, const char* sourceFile, int sourceLine,
     62             const char* tag, const char* format, va_list args) {
     63  CSFLogV(SDPToCSFLogLevel(priority), sourceFile, sourceLine, tag, format,
     64          args);
     65 }
     66 
     67 int SDPLogTestLevel(SDPLogLevel priority) {
     68  return CSFLogTestLevel(SDPToCSFLogLevel(priority));
     69 }