image/public/ImageLogging.h

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:28a8606ecc93
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 ImageLogging_h
8 #define ImageLogging_h
9
10 // In order for FORCE_PR_LOG below to work, we have to define it before the
11 // first time prlog is #included.
12 #if defined(PR_LOG)
13 #error "Must #include ImageLogging.h before before any IPDL-generated files or other files that #include prlog.h."
14 #endif
15
16 #if defined(MOZ_LOGGING)
17 #define FORCE_PR_LOG
18 #endif
19
20 #include "prlog.h"
21 #include "prinrval.h"
22 #include "nsString.h"
23
24 #if defined(PR_LOGGING)
25 // Declared in imgRequest.cpp.
26 extern PRLogModuleInfo *GetImgLog();
27
28 #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
29
30 class LogScope {
31 public:
32 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn) :
33 mLog(aLog), mFrom(from), mFunc(fn)
34 {
35 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n",
36 GIVE_ME_MS_NOW(), mFrom, mFunc));
37 }
38
39 /* const char * constructor */
40 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
41 const char *paramName, const char *paramValue) :
42 mLog(aLog), mFrom(from), mFunc(fn)
43 {
44 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
45 GIVE_ME_MS_NOW(), mFrom, mFunc,
46 paramName, paramValue));
47 }
48
49 /* void ptr constructor */
50 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
51 const char *paramName, const void *paramValue) :
52 mLog(aLog), mFrom(from), mFunc(fn)
53 {
54 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
55 GIVE_ME_MS_NOW(), mFrom, mFunc,
56 paramName, paramValue));
57 }
58
59 /* int32_t constructor */
60 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
61 const char *paramName, int32_t paramValue) :
62 mLog(aLog), mFrom(from), mFunc(fn)
63 {
64 PR_LOG(mLog, PR_LOG_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 LogScope(PRLogModuleInfo *aLog, void *from, const char *fn,
71 const char *paramName, uint32_t paramValue) :
72 mLog(aLog), mFrom(from), mFunc(fn)
73 {
74 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
75 GIVE_ME_MS_NOW(), mFrom, mFunc,
76 paramName, paramValue));
77 }
78
79
80 ~LogScope() {
81 PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n",
82 GIVE_ME_MS_NOW(), mFrom, mFunc));
83 }
84
85 private:
86 PRLogModuleInfo *mLog;
87 void *mFrom;
88 const char *mFunc;
89 };
90
91
92 class LogFunc {
93 public:
94 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn)
95 {
96 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n",
97 GIVE_ME_MS_NOW(), from, fn));
98 }
99
100 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
101 const char *paramName, const char *paramValue)
102 {
103 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n",
104 GIVE_ME_MS_NOW(), from, fn,
105 paramName, paramValue));
106 }
107
108 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
109 const char *paramName, const void *paramValue)
110 {
111 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n",
112 GIVE_ME_MS_NOW(), from, fn,
113 paramName, paramValue));
114 }
115
116
117 LogFunc(PRLogModuleInfo *aLog, void *from, const char *fn,
118 const char *paramName, uint32_t paramValue)
119 {
120 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n",
121 GIVE_ME_MS_NOW(), from,
122 fn,
123 paramName, paramValue));
124 }
125
126 };
127
128
129 class LogMessage {
130 public:
131 LogMessage(PRLogModuleInfo *aLog, void *from, const char *fn,
132 const char *msg)
133 {
134 PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n",
135 GIVE_ME_MS_NOW(), from, fn, msg));
136 }
137 };
138
139 #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
140 #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
141 #define LOG_SCOPE_APPEND_LINE_NUMBER(id) LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
142
143 #define LOG_SCOPE(l, s) \
144 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s)
145
146 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
147 LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv)
148
149 #define LOG_FUNC(l, s) LogFunc(l, this, s)
150
151 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
152
153 #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
154
155 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
156
157
158
159 #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
160
161 #else
162
163 #define LOG_SCOPE(l, s)
164 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
165 #define LOG_FUNC(l, s)
166 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv)
167 #define LOG_STATIC_FUNC(l, s)
168 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv)
169 #define LOG_MSG(l, s, m)
170
171 #endif // if defined(PR_LOGGING)
172
173 #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
174
175 #endif // ifndef ImageLogging_h

mercurial