Line data Source code
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 93 : LogScope(mozilla::LogModule* aLog, void* aFrom, const char* aFunc)
25 0 : : mLog(aLog)
26 : , mFrom(aFrom)
27 0 : , mFunc(aFunc)
28 : {
29 0 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {ENTER}\n",
30 : GIVE_ME_MS_NOW(), mFrom, mFunc));
31 93 : }
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 : {
40 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
41 : GIVE_ME_MS_NOW(), mFrom, mFunc,
42 : paramName, paramValue));
43 : }
44 :
45 : /* void ptr constructor */
46 0 : LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
47 : const char* paramName, const void* paramValue)
48 0 : : mLog(aLog)
49 : , mFrom(from)
50 0 : , mFunc(fn)
51 : {
52 137 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
53 : GIVE_ME_MS_NOW(), mFrom, mFunc,
54 : paramName, paramValue));
55 137 : }
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 : {
64 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
65 : GIVE_ME_MS_NOW(), mFrom, mFunc,
66 : paramName, paramValue));
67 : }
68 :
69 : /* uint32_t constructor */
70 0 : LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
71 : const char* paramName, uint32_t paramValue)
72 0 : : mLog(aLog)
73 : , mFrom(from)
74 0 : , mFunc(fn)
75 : {
76 16 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
77 : GIVE_ME_MS_NOW(), mFrom, mFunc,
78 : paramName, paramValue));
79 0 : }
80 :
81 : /* nsIURI constructor */
82 57 : LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
83 : const char* paramName, nsIURI* aURI)
84 57 : : mLog(aLog)
85 : , mFrom(from)
86 57 : , mFunc(fn)
87 : {
88 57 : if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
89 : 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 : }
96 : }
97 0 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
98 : GIVE_ME_MS_NOW(), from, fn,
99 : paramName, spec.get()));
100 : }
101 57 : }
102 :
103 : /* Image constructor */
104 40 : LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
105 : const char* paramName, mozilla::image::Image* aImage)
106 40 : : LogScope(aLog, from, fn, paramName, aImage ? aImage->GetURI() : nullptr)
107 : {
108 40 : }
109 :
110 0 : ~LogScope()
111 303 : {
112 303 : MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {EXIT}\n",
113 : GIVE_ME_MS_NOW(), mFrom, mFunc));
114 303 : }
115 :
116 : private:
117 : mozilla::LogModule* mLog;
118 : void* mFrom;
119 : const char* mFunc;
120 : };
121 :
122 : class LogFunc {
123 : public:
124 236 : LogFunc(mozilla::LogModule* aLog, void* from, const char* fn)
125 : {
126 236 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s\n",
127 : GIVE_ME_MS_NOW(), from, fn));
128 236 : }
129 :
130 301 : LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
131 : const char* paramName, const char* paramValue)
132 : {
133 301 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n",
134 : GIVE_ME_MS_NOW(), from, fn,
135 : paramName, paramValue));
136 : }
137 :
138 : LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
139 : const char* paramName, const void* paramValue)
140 : {
141 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%p\")\n",
142 : GIVE_ME_MS_NOW(), from, fn,
143 : paramName, paramValue));
144 : }
145 :
146 :
147 : LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
148 : const char* paramName, uint32_t paramValue)
149 : {
150 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\")\n",
151 : GIVE_ME_MS_NOW(), from, fn,
152 : paramName, paramValue));
153 : }
154 :
155 : LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
156 : const char* paramName, nsIURI* aURI)
157 : {
158 : if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
159 : static const size_t sMaxTruncatedLength = 1024;
160 : nsAutoCString spec("<unknown>");
161 : if (aURI) {
162 : aURI->GetSpec(spec);
163 : if (spec.Length() >= sMaxTruncatedLength) {
164 : spec.Truncate(sMaxTruncatedLength);
165 : }
166 : }
167 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n",
168 : GIVE_ME_MS_NOW(), from, fn,
169 : paramName, spec.get()));
170 : }
171 : }
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 : {
177 : }
178 :
179 : };
180 :
181 :
182 : class LogMessage {
183 : public:
184 : LogMessage(mozilla::LogModule* aLog, void* from, const char* fn,
185 : const char* msg)
186 : {
187 : MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s -- %s\n",
188 : GIVE_ME_MS_NOW(), from, fn, msg));
189 : }
190 : };
191 :
192 : #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
193 : #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) \
194 : LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
195 : #define LOG_SCOPE_APPEND_LINE_NUMBER(id) \
196 : LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
197 :
198 : #define LOG_SCOPE(l, s) \
199 : 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 : LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv)
203 :
204 : #define LOG_FUNC(l, s) LogFunc(l, this, s)
205 :
206 : #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
207 :
208 : #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
209 :
210 : #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
211 :
212 : #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
213 :
214 : #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
215 :
216 : #endif // mozilla_image_ImageLogging_h
|