michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ImageLogging_h michael@0: #define ImageLogging_h michael@0: michael@0: // In order for FORCE_PR_LOG below to work, we have to define it before the michael@0: // first time prlog is #included. michael@0: #if defined(PR_LOG) michael@0: #error "Must #include ImageLogging.h before before any IPDL-generated files or other files that #include prlog.h." michael@0: #endif michael@0: michael@0: #if defined(MOZ_LOGGING) michael@0: #define FORCE_PR_LOG michael@0: #endif michael@0: michael@0: #include "prlog.h" michael@0: #include "prinrval.h" michael@0: #include "nsString.h" michael@0: michael@0: #if defined(PR_LOGGING) michael@0: // Declared in imgRequest.cpp. michael@0: extern PRLogModuleInfo *GetImgLog(); michael@0: michael@0: #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow()) michael@0: michael@0: class LogScope { michael@0: public: michael@0: LogScope(PRLogModuleInfo *aLog, void *from, const char *fn) : michael@0: mLog(aLog), mFrom(from), mFunc(fn) michael@0: { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc)); michael@0: } michael@0: michael@0: /* const char * constructor */ michael@0: LogScope(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, const char *paramValue) : michael@0: mLog(aLog), mFrom(from), mFunc(fn) michael@0: { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: /* void ptr constructor */ michael@0: LogScope(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, const void *paramValue) : michael@0: mLog(aLog), mFrom(from), mFunc(fn) michael@0: { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: /* int32_t constructor */ michael@0: LogScope(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, int32_t paramValue) : michael@0: mLog(aLog), mFrom(from), mFunc(fn) michael@0: { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: /* uint32_t constructor */ michael@0: LogScope(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, uint32_t paramValue) : michael@0: mLog(aLog), mFrom(from), mFunc(fn) michael@0: { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: michael@0: ~LogScope() { michael@0: PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n", michael@0: GIVE_ME_MS_NOW(), mFrom, mFunc)); michael@0: } michael@0: michael@0: private: michael@0: PRLogModuleInfo *mLog; michael@0: void *mFrom; michael@0: const char *mFunc; michael@0: }; michael@0: michael@0: michael@0: class LogFunc { michael@0: public: michael@0: LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn) michael@0: { michael@0: PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n", michael@0: GIVE_ME_MS_NOW(), from, fn)); michael@0: } michael@0: michael@0: LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, const char *paramValue) michael@0: { michael@0: PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n", michael@0: GIVE_ME_MS_NOW(), from, fn, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, const void *paramValue) michael@0: { michael@0: PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n", michael@0: GIVE_ME_MS_NOW(), from, fn, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: michael@0: LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *paramName, uint32_t paramValue) michael@0: { michael@0: PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n", michael@0: GIVE_ME_MS_NOW(), from, michael@0: fn, michael@0: paramName, paramValue)); michael@0: } michael@0: michael@0: }; michael@0: michael@0: michael@0: class LogMessage { michael@0: public: michael@0: LogMessage(PRLogModuleInfo *aLog, void *from, const char *fn, michael@0: const char *msg) michael@0: { michael@0: PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n", michael@0: GIVE_ME_MS_NOW(), from, fn, msg)); michael@0: } michael@0: }; michael@0: michael@0: #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line michael@0: #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) michael@0: #define LOG_SCOPE_APPEND_LINE_NUMBER(id) LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__) michael@0: michael@0: #define LOG_SCOPE(l, s) \ michael@0: LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s) michael@0: michael@0: #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \ michael@0: LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv) michael@0: michael@0: #define LOG_FUNC(l, s) LogFunc(l, this, s) michael@0: michael@0: #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv) michael@0: michael@0: #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s) michael@0: michael@0: #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv) michael@0: michael@0: michael@0: michael@0: #define LOG_MSG(l, s, m) LogMessage(l, this, s, m) michael@0: michael@0: #else michael@0: michael@0: #define LOG_SCOPE(l, s) michael@0: #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) michael@0: #define LOG_FUNC(l, s) michael@0: #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) michael@0: #define LOG_STATIC_FUNC(l, s) michael@0: #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) michael@0: #define LOG_MSG(l, s, m) michael@0: michael@0: #endif // if defined(PR_LOGGING) michael@0: michael@0: #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM michael@0: michael@0: #endif // ifndef ImageLogging_h