1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 2001
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Stuart Parmenter <pavlov@netscape.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef ImageLogging_h
41 : #define ImageLogging_h
42 :
43 : // In order for FORCE_PR_LOG below to work, we have to define it before the
44 : // first time prlog is #included.
45 : #if defined(PR_LOG)
46 : #error "Must #include ImageLogging.h before before any IPDL-generated files or other files that #include prlog.h."
47 : #endif
48 :
49 : #if defined(MOZ_LOGGING)
50 : #define FORCE_PR_LOG
51 : #endif
52 :
53 : #include "prlog.h"
54 : #include "prinrval.h"
55 : #include "nsString.h"
56 :
57 : #if defined(PR_LOGGING)
58 : // Declared in imgRequest.cpp.
59 : extern PRLogModuleInfo *gImgLog;
60 :
61 : #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
62 :
63 : class LogScope {
64 : public:
65 144 : LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn) :
66 144 : mLog(aLog), mFrom(from), mFunc(fn)
67 : {
68 144 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n",
69 : GIVE_ME_MS_NOW(),
70 : mFrom, mFunc.get()));
71 144 : }
72 :
73 : /* const char * constructor */
74 30 : LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
75 : const nsDependentCString ¶mName, const char *paramValue) :
76 30 : mLog(aLog), mFrom(from), mFunc(fn)
77 : {
78 30 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
79 : GIVE_ME_MS_NOW(),
80 : mFrom, mFunc.get(),
81 : paramName.get(),
82 : paramValue));
83 30 : }
84 :
85 : /* void ptr constructor */
86 100 : LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
87 : const nsDependentCString ¶mName, const void *paramValue) :
88 100 : mLog(aLog), mFrom(from), mFunc(fn)
89 : {
90 100 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
91 : GIVE_ME_MS_NOW(),
92 : mFrom, mFunc.get(),
93 : paramName.get(),
94 : paramValue));
95 100 : }
96 :
97 : /* PRInt32 constructor */
98 : LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
99 : const nsDependentCString ¶mName, PRInt32 paramValue) :
100 : mLog(aLog), mFrom(from), mFunc(fn)
101 : {
102 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
103 : GIVE_ME_MS_NOW(),
104 : mFrom, mFunc.get(),
105 : paramName.get(),
106 : paramValue));
107 : }
108 :
109 : /* PRUint32 constructor */
110 8 : LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
111 : const nsDependentCString ¶mName, PRUint32 paramValue) :
112 8 : mLog(aLog), mFrom(from), mFunc(fn)
113 : {
114 8 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
115 : GIVE_ME_MS_NOW(),
116 : mFrom, mFunc.get(),
117 : paramName.get(),
118 : paramValue));
119 8 : }
120 :
121 :
122 564 : ~LogScope() {
123 282 : PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n",
124 : GIVE_ME_MS_NOW(),
125 : mFrom, mFunc.get()));
126 282 : }
127 :
128 : private:
129 : PRLogModuleInfo *mLog;
130 : void *mFrom;
131 : nsCAutoString mFunc;
132 : };
133 :
134 :
135 : class LogFunc {
136 : public:
137 458 : LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn)
138 : {
139 458 : PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n",
140 : GIVE_ME_MS_NOW(), from,
141 : fn.get()));
142 458 : }
143 :
144 131 : LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
145 : const nsDependentCString ¶mName, const char *paramValue)
146 : {
147 131 : PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n",
148 : GIVE_ME_MS_NOW(), from,
149 : fn.get(),
150 : paramName.get(), paramValue));
151 131 : }
152 :
153 5 : LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
154 : const nsDependentCString ¶mName, const void *paramValue)
155 : {
156 5 : PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n",
157 : GIVE_ME_MS_NOW(), from,
158 : fn.get(),
159 : paramName.get(), paramValue));
160 5 : }
161 :
162 :
163 16 : LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
164 : const nsDependentCString ¶mName, PRUint32 paramValue)
165 : {
166 16 : PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n",
167 : GIVE_ME_MS_NOW(), from,
168 : fn.get(),
169 : paramName.get(), paramValue));
170 16 : }
171 :
172 : };
173 :
174 :
175 : class LogMessage {
176 : public:
177 13 : LogMessage(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
178 : const nsDependentCString &msg)
179 : {
180 13 : PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n",
181 : GIVE_ME_MS_NOW(), from,
182 : fn.get(),
183 : msg.get()));
184 13 : }
185 : };
186 :
187 : #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
188 : #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
189 : #define LOG_SCOPE_APPEND_LINE_NUMBER(id) LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
190 :
191 : #define LOG_SCOPE(l, s) \
192 : LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, \
193 : static_cast<void *>(this), \
194 : NS_LITERAL_CSTRING(s))
195 :
196 : #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
197 : LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, \
198 : static_cast<void *>(this), \
199 : NS_LITERAL_CSTRING(s), \
200 : NS_LITERAL_CSTRING(pn), pv)
201 :
202 : #define LOG_FUNC(l, s) \
203 : LogFunc(l, \
204 : static_cast<void *>(this), \
205 : NS_LITERAL_CSTRING(s))
206 :
207 : #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) \
208 : LogFunc(l, \
209 : static_cast<void *>(this), \
210 : NS_LITERAL_CSTRING(s), \
211 : NS_LITERAL_CSTRING(pn), pv)
212 :
213 : #define LOG_STATIC_FUNC(l, s) \
214 : LogFunc(l, \
215 : nsnull, \
216 : NS_LITERAL_CSTRING(s))
217 :
218 : #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) \
219 : LogFunc(l, \
220 : nsnull, \
221 : NS_LITERAL_CSTRING(s), \
222 : NS_LITERAL_CSTRING(pn), pv)
223 :
224 :
225 :
226 : #define LOG_MSG(l, s, m) \
227 : LogMessage(l, \
228 : static_cast<void *>(this), \
229 : NS_LITERAL_CSTRING(s), \
230 : NS_LITERAL_CSTRING(m))
231 :
232 : #else
233 :
234 : #define LOG_SCOPE(l, s)
235 : #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
236 : #define LOG_FUNC(l, s)
237 : #define LOG_FUNC_WITH_PARAM(l, s, pn, pv)
238 : #define LOG_STATIC_FUNC(l, s)
239 : #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv)
240 : #define LOG_MSG(l, s, m)
241 :
242 : #endif // if defined(PR_LOGGING)
243 :
244 : #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
245 :
246 : #endif // ifndef ImageLogging_h
|