image/public/ImageLogging.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  *
     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
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef ImageLogging_h
     8 #define ImageLogging_h
    10 // In order for FORCE_PR_LOG below to work, we have to define it before the
    11 // first time prlog is #included.
    12 #if defined(PR_LOG)
    13 #error "Must #include ImageLogging.h before before any IPDL-generated files or other files that #include prlog.h."
    14 #endif
    16 #if defined(MOZ_LOGGING)
    17 #define FORCE_PR_LOG
    18 #endif
    20 #include "prlog.h"
    21 #include "prinrval.h"
    22 #include "nsString.h"
    24 #if defined(PR_LOGGING)
    25 // Declared in imgRequest.cpp.
    26 extern PRLogModuleInfo *GetImgLog();
    28 #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
    30 class LogScope {
    31 public:
    32   LogScope(PRLogModuleInfo *aLog, void *from, const char *fn) :
    33     mLog(aLog), mFrom(from), mFunc(fn)
    34   {
    35     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n",
    36                                    GIVE_ME_MS_NOW(), mFrom, mFunc));
    37   }
    39   /* const char * constructor */
    40   LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
    41            const char *paramName, const char *paramValue) :
    42     mLog(aLog), mFrom(from), mFunc(fn)
    43   {
    44     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
    45                                    GIVE_ME_MS_NOW(), mFrom, mFunc,
    46                                    paramName, paramValue));
    47   }
    49   /* void ptr constructor */
    50   LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
    51            const char *paramName, const void *paramValue) :
    52     mLog(aLog), mFrom(from), mFunc(fn)
    53   {
    54     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
    55                                    GIVE_ME_MS_NOW(), mFrom, mFunc,
    56                                    paramName, paramValue));
    57   }
    59   /* int32_t constructor */
    60   LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
    61            const char *paramName, int32_t paramValue) :
    62     mLog(aLog), mFrom(from), mFunc(fn)
    63   {
    64     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
    65                                    GIVE_ME_MS_NOW(), mFrom, mFunc,
    66                                    paramName, paramValue));
    67   }
    69   /* uint32_t constructor */
    70   LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
    71            const char *paramName, uint32_t paramValue) :
    72     mLog(aLog), mFrom(from), mFunc(fn)
    73   {
    74     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
    75                                    GIVE_ME_MS_NOW(), mFrom, mFunc,
    76                                    paramName, paramValue));
    77   }
    80   ~LogScope() {
    81     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n",
    82                                    GIVE_ME_MS_NOW(), mFrom, mFunc));
    83   }
    85 private:
    86   PRLogModuleInfo *mLog;
    87   void *mFrom;
    88   const char *mFunc;
    89 };
    92 class LogFunc {
    93 public:
    94   LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn)
    95   {
    96     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n",
    97                                 GIVE_ME_MS_NOW(), from, fn));
    98   }
   100   LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
   101           const char *paramName, const char *paramValue)
   102   {
   103     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n",
   104                                 GIVE_ME_MS_NOW(), from, fn,
   105                                 paramName, paramValue));
   106   }
   108   LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
   109           const char *paramName, const void *paramValue)
   110   {
   111     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n",
   112                                 GIVE_ME_MS_NOW(), from, fn,
   113                                 paramName, paramValue));
   114   }
   117   LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
   118           const char *paramName, uint32_t paramValue)
   119   {
   120     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n",
   121                                 GIVE_ME_MS_NOW(), from,
   122                                 fn,
   123                                 paramName, paramValue));
   124   }
   126 };
   129 class LogMessage {
   130 public:
   131   LogMessage(PRLogModuleInfo *aLog, void *from, const char *fn,
   132              const char *msg)
   133   {
   134     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n",
   135                                 GIVE_ME_MS_NOW(), from, fn, msg));
   136   }
   137 };
   139 #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
   140 #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
   141 #define LOG_SCOPE_APPEND_LINE_NUMBER(id) LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
   143 #define LOG_SCOPE(l, s) \
   144   LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s)
   146 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
   147   LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv)
   149 #define LOG_FUNC(l, s) LogFunc(l, this, s)
   151 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
   153 #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
   155 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
   159 #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
   161 #else
   163 #define LOG_SCOPE(l, s)
   164 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
   165 #define LOG_FUNC(l, s)
   166 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv)
   167 #define LOG_STATIC_FUNC(l, s)
   168 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv)
   169 #define LOG_MSG(l, s, m)
   171 #endif // if defined(PR_LOGGING)
   173 #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
   175 #endif // ifndef ImageLogging_h

mercurial