/src/mozilla-central/image/ImageLogging.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozilla_image_ImageLogging_h |
8 | | #define mozilla_image_ImageLogging_h |
9 | | |
10 | | #include "mozilla/Logging.h" |
11 | | #include "Image.h" |
12 | | #include "nsIURI.h" |
13 | | #include "prinrval.h" |
14 | | |
15 | | static mozilla::LazyLogModule gImgLog("imgRequest"); |
16 | | |
17 | | #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow()) |
18 | | |
19 | | using mozilla::LogLevel; |
20 | | |
21 | | class LogScope { |
22 | | public: |
23 | | |
24 | | LogScope(mozilla::LogModule* aLog, void* aFrom, const char* aFunc) |
25 | | : mLog(aLog) |
26 | | , mFrom(aFrom) |
27 | | , mFunc(aFunc) |
28 | 0 | { |
29 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {ENTER}\n", |
30 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc)); |
31 | 0 | } |
32 | | |
33 | | /* const char * constructor */ |
34 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
35 | | const char* paramName, const char* paramValue) |
36 | | : mLog(aLog) |
37 | | , mFrom(from) |
38 | | , mFunc(fn) |
39 | 0 | { |
40 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n", |
41 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc, |
42 | 0 | paramName, paramValue)); |
43 | 0 | } |
44 | | |
45 | | /* void ptr constructor */ |
46 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
47 | | const char* paramName, const void* paramValue) |
48 | | : mLog(aLog) |
49 | | , mFrom(from) |
50 | | , mFunc(fn) |
51 | 0 | { |
52 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=%p) {ENTER}\n", |
53 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc, |
54 | 0 | paramName, paramValue)); |
55 | 0 | } |
56 | | |
57 | | /* int32_t constructor */ |
58 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
59 | | const char* paramName, int32_t paramValue) |
60 | | : mLog(aLog) |
61 | | , mFrom(from) |
62 | | , mFunc(fn) |
63 | 0 | { |
64 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", |
65 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc, |
66 | 0 | paramName, paramValue)); |
67 | 0 | } |
68 | | |
69 | | /* uint32_t constructor */ |
70 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
71 | | const char* paramName, uint32_t paramValue) |
72 | | : mLog(aLog) |
73 | | , mFrom(from) |
74 | | , mFunc(fn) |
75 | 0 | { |
76 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n", |
77 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc, |
78 | 0 | paramName, paramValue)); |
79 | 0 | } |
80 | | |
81 | | /* nsIURI constructor */ |
82 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
83 | | const char* paramName, nsIURI* aURI) |
84 | | : mLog(aLog) |
85 | | , mFrom(from) |
86 | | , mFunc(fn) |
87 | 0 | { |
88 | 0 | if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { |
89 | 0 | static const size_t sMaxTruncatedLength = 1024; |
90 | 0 | nsAutoCString spec("<unknown>"); |
91 | 0 | if (aURI) { |
92 | 0 | aURI->GetSpec(spec); |
93 | 0 | if (spec.Length() >= sMaxTruncatedLength) { |
94 | 0 | spec.Truncate(sMaxTruncatedLength); |
95 | 0 | } |
96 | 0 | } |
97 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n", |
98 | 0 | GIVE_ME_MS_NOW(), from, fn, |
99 | 0 | paramName, spec.get())); |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | | /* Image constructor */ |
104 | | LogScope(mozilla::LogModule* aLog, void* from, const char* fn, |
105 | | const char* paramName, mozilla::image::Image* aImage) |
106 | | : LogScope(aLog, from, fn, paramName, aImage ? aImage->GetURI() : nullptr) |
107 | 0 | { |
108 | 0 | } |
109 | | |
110 | | ~LogScope() |
111 | 0 | { |
112 | 0 | MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {EXIT}\n", |
113 | 0 | GIVE_ME_MS_NOW(), mFrom, mFunc)); |
114 | 0 | } |
115 | | |
116 | | private: |
117 | | mozilla::LogModule* mLog; |
118 | | void* mFrom; |
119 | | const char* mFunc; |
120 | | }; |
121 | | |
122 | | class LogFunc { |
123 | | public: |
124 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn) |
125 | 0 | { |
126 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s\n", |
127 | 0 | GIVE_ME_MS_NOW(), from, fn)); |
128 | 0 | } |
129 | | |
130 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn, |
131 | | const char* paramName, const char* paramValue) |
132 | 0 | { |
133 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n", |
134 | 0 | GIVE_ME_MS_NOW(), from, fn, |
135 | 0 | paramName, paramValue)); |
136 | 0 | } |
137 | | |
138 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn, |
139 | | const char* paramName, const void* paramValue) |
140 | 0 | { |
141 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%p\")\n", |
142 | 0 | GIVE_ME_MS_NOW(), from, fn, |
143 | 0 | paramName, paramValue)); |
144 | 0 | } |
145 | | |
146 | | |
147 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn, |
148 | | const char* paramName, uint32_t paramValue) |
149 | 0 | { |
150 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\")\n", |
151 | 0 | GIVE_ME_MS_NOW(), from, fn, |
152 | 0 | paramName, paramValue)); |
153 | 0 | } |
154 | | |
155 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn, |
156 | | const char* paramName, nsIURI* aURI) |
157 | 0 | { |
158 | 0 | if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) { |
159 | 0 | static const size_t sMaxTruncatedLength = 1024; |
160 | 0 | nsAutoCString spec("<unknown>"); |
161 | 0 | if (aURI) { |
162 | 0 | aURI->GetSpec(spec); |
163 | 0 | if (spec.Length() >= sMaxTruncatedLength) { |
164 | 0 | spec.Truncate(sMaxTruncatedLength); |
165 | 0 | } |
166 | 0 | } |
167 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n", |
168 | 0 | GIVE_ME_MS_NOW(), from, fn, |
169 | 0 | paramName, spec.get())); |
170 | 0 | } |
171 | 0 | } |
172 | | |
173 | | LogFunc(mozilla::LogModule* aLog, void* from, const char* fn, |
174 | | const char* paramName, mozilla::image::Image* aImage) |
175 | | : LogFunc(aLog, from, fn, paramName, aImage ? aImage->GetURI() : nullptr) |
176 | 0 | { |
177 | 0 | } |
178 | | |
179 | | }; |
180 | | |
181 | | |
182 | | class LogMessage { |
183 | | public: |
184 | | LogMessage(mozilla::LogModule* aLog, void* from, const char* fn, |
185 | | const char* msg) |
186 | 0 | { |
187 | 0 | MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s -- %s\n", |
188 | 0 | GIVE_ME_MS_NOW(), from, fn, msg)); |
189 | 0 | } |
190 | | }; |
191 | | |
192 | 0 | #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line |
193 | | #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) \ |
194 | 0 | LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) |
195 | | #define LOG_SCOPE_APPEND_LINE_NUMBER(id) \ |
196 | 0 | LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__) |
197 | | |
198 | | #define LOG_SCOPE(l, s) \ |
199 | 0 | LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s) |
200 | | |
201 | | #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \ |
202 | 0 | LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv) |
203 | | |
204 | 0 | #define LOG_FUNC(l, s) LogFunc(l, this, s) |
205 | | |
206 | 0 | #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv) |
207 | | |
208 | 0 | #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s) |
209 | | |
210 | 0 | #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv) |
211 | | |
212 | 0 | #define LOG_MSG(l, s, m) LogMessage(l, this, s, m) |
213 | | |
214 | 0 | #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM |
215 | | |
216 | | #endif // mozilla_image_ImageLogging_h |