Bug 1860954 clarify that gGraphs is not used for offline graphs r=pehrsons
[gecko.git] / image / ImageLogging.h
blobc36f4e8dbdac3014a8a142132adfa51a3613f466
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 mozilla_image_ImageLogging_h
8 #define mozilla_image_ImageLogging_h
10 #include "mozilla/Logging.h"
11 #include "Image.h"
12 #include "nsIURI.h"
13 #include "prinrval.h"
15 static mozilla::LazyLogModule gImgLog("imgRequest");
17 #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
19 using mozilla::LogLevel;
21 class LogScope {
22 public:
23 LogScope(mozilla::LogModule* aLog, void* aFrom, const char* aFunc)
24 : mLog(aLog), mFrom(aFrom), mFunc(aFunc) {
25 MOZ_LOG(mLog, LogLevel::Debug,
26 ("%d [this=%p] %s {ENTER}\n", GIVE_ME_MS_NOW(), mFrom, mFunc));
29 /* const char * constructor */
30 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
31 const char* paramName, const char* paramValue)
32 : mLog(aLog), mFrom(from), mFunc(fn) {
33 MOZ_LOG(mLog, LogLevel::Debug,
34 ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n", GIVE_ME_MS_NOW(), mFrom,
35 mFunc, paramName, paramValue));
38 /* void ptr constructor */
39 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
40 const char* paramName, const void* paramValue)
41 : mLog(aLog), mFrom(from), mFunc(fn) {
42 MOZ_LOG(mLog, LogLevel::Debug,
43 ("%d [this=%p] %s (%s=%p) {ENTER}\n", GIVE_ME_MS_NOW(), mFrom,
44 mFunc, paramName, paramValue));
47 /* int32_t constructor */
48 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
49 const char* paramName, int32_t paramValue)
50 : mLog(aLog), mFrom(from), mFunc(fn) {
51 MOZ_LOG(mLog, LogLevel::Debug,
52 ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", GIVE_ME_MS_NOW(), mFrom,
53 mFunc, paramName, paramValue));
56 /* uint32_t constructor */
57 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
58 const char* paramName, uint32_t paramValue)
59 : mLog(aLog), mFrom(from), mFunc(fn) {
60 MOZ_LOG(mLog, LogLevel::Debug,
61 ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", GIVE_ME_MS_NOW(), mFrom,
62 mFunc, paramName, paramValue));
65 /* nsIURI constructor */
66 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
67 const char* paramName, nsIURI* aURI)
68 : mLog(aLog), mFrom(from), mFunc(fn) {
69 if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
70 static const size_t sMaxTruncatedLength = 1024;
71 nsAutoCString spec("<unknown>");
72 if (aURI) {
73 aURI->GetSpec(spec);
74 if (spec.Length() >= sMaxTruncatedLength) {
75 spec.Truncate(sMaxTruncatedLength);
78 MOZ_LOG(aLog, LogLevel::Debug,
79 ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n", GIVE_ME_MS_NOW(), from,
80 fn, paramName, spec.get()));
84 /* Image constructor */
85 LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
86 const char* paramName, mozilla::image::Image* aImage)
87 : LogScope(aLog, from, fn, paramName,
88 aImage ? aImage->GetURI() : nullptr) {}
90 ~LogScope() {
91 MOZ_LOG(mLog, LogLevel::Debug,
92 ("%d [this=%p] %s {EXIT}\n", GIVE_ME_MS_NOW(), mFrom, mFunc));
95 private:
96 mozilla::LogModule* mLog;
97 void* mFrom;
98 const char* mFunc;
101 class LogFunc {
102 public:
103 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn) {
104 MOZ_LOG(aLog, LogLevel::Debug,
105 ("%d [this=%p] %s\n", GIVE_ME_MS_NOW(), from, fn));
108 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
109 const char* paramName, const char* paramValue) {
110 MOZ_LOG(aLog, LogLevel::Debug,
111 ("%d [this=%p] %s (%s=\"%s\")\n", GIVE_ME_MS_NOW(), from, fn,
112 paramName, paramValue));
115 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
116 const char* paramName, const void* paramValue) {
117 MOZ_LOG(aLog, LogLevel::Debug,
118 ("%d [this=%p] %s (%s=\"%p\")\n", GIVE_ME_MS_NOW(), from, fn,
119 paramName, paramValue));
122 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
123 const char* paramName, uint32_t paramValue) {
124 MOZ_LOG(aLog, LogLevel::Debug,
125 ("%d [this=%p] %s (%s=\"%d\")\n", GIVE_ME_MS_NOW(), from, fn,
126 paramName, paramValue));
129 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
130 const char* paramName, nsIURI* aURI) {
131 if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
132 static const size_t sMaxTruncatedLength = 1024;
133 nsAutoCString spec("<unknown>");
134 if (aURI) {
135 aURI->GetSpec(spec);
136 if (spec.Length() >= sMaxTruncatedLength) {
137 spec.Truncate(sMaxTruncatedLength);
140 MOZ_LOG(aLog, LogLevel::Debug,
141 ("%d [this=%p] %s (%s=\"%s\")\n", GIVE_ME_MS_NOW(), from, fn,
142 paramName, spec.get()));
146 LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
147 const char* paramName, mozilla::image::Image* aImage)
148 : LogFunc(aLog, from, fn, paramName,
149 aImage ? aImage->GetURI() : nullptr) {}
152 class LogMessage {
153 public:
154 LogMessage(mozilla::LogModule* aLog, void* from, const char* fn,
155 const char* msg) {
156 MOZ_LOG(aLog, LogLevel::Debug,
157 ("%d [this=%p] %s -- %s\n", GIVE_ME_MS_NOW(), from, fn, msg));
161 #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id##line
162 #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) \
163 LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
164 #define LOG_SCOPE_APPEND_LINE_NUMBER(id) \
165 LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
167 #define LOG_SCOPE(l, s) \
168 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR)(l, this, s)
170 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
171 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR)(l, this, s, pn, pv)
173 #define LOG_FUNC(l, s) LogFunc(l, this, s)
175 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
177 #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
179 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
181 #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
183 #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
185 #endif // mozilla_image_ImageLogging_h