1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef prlog_h___
|
---|
39 | #define prlog_h___
|
---|
40 |
|
---|
41 | #include "prtypes.h"
|
---|
42 |
|
---|
43 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
44 | #define PR_NewLogModule VBoxNsprPR_NewLogModule
|
---|
45 | #define PR_SetLogFile VBoxNsprPR_SetLogFile
|
---|
46 | #define PR_SetLogBuffering VBoxNsprPR_SetLogBuffering
|
---|
47 | #define PR_LogPrint VBoxNsprPR_LogPrint
|
---|
48 | #define PR_LogFlush VBoxNsprPR_LogFlush
|
---|
49 | #define PR_Assert VBoxNsprPR_Assert
|
---|
50 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
51 |
|
---|
52 | PR_BEGIN_EXTERN_C
|
---|
53 |
|
---|
54 | /*
|
---|
55 | ** prlog.h -- Declare interfaces to NSPR's Logging service
|
---|
56 | **
|
---|
57 | ** NSPR provides a logging service that is used by NSPR itself and is
|
---|
58 | ** available to client programs.
|
---|
59 | **
|
---|
60 | ** To use the service from a client program, you should create a
|
---|
61 | ** PRLogModuleInfo structure by calling PR_NewLogModule(). After
|
---|
62 | ** creating the LogModule, you can write to the log using the PR_LOG()
|
---|
63 | ** macro.
|
---|
64 | **
|
---|
65 | ** Initialization of the log service is handled by NSPR initialization.
|
---|
66 | **
|
---|
67 | ** At execution time, you must enable the log service. To enable the
|
---|
68 | ** log service, set the environment variable: NSPR_LOG_MODULES
|
---|
69 | ** variable.
|
---|
70 | **
|
---|
71 | ** NSPR_LOG_MODULES variable has the form:
|
---|
72 | **
|
---|
73 | ** <moduleName>:<value>[, <moduleName>:<value>]*
|
---|
74 | **
|
---|
75 | ** Where:
|
---|
76 | ** <moduleName> is the name passed to PR_NewLogModule().
|
---|
77 | ** <value> is a numeric constant, e.g. 5. This value is the maximum
|
---|
78 | ** value of a log event, enumerated by PRLogModuleLevel, that you want
|
---|
79 | ** written to the log.
|
---|
80 | **
|
---|
81 | ** For example: to record all events of greater value than or equal to
|
---|
82 | ** PR_LOG_ERROR for a LogModule names "gizmo", say:
|
---|
83 | **
|
---|
84 | ** set NSPR_LOG_MODULES=gizmo:2
|
---|
85 | **
|
---|
86 | ** Note that you must specify the numeric value of PR_LOG_ERROR.
|
---|
87 | **
|
---|
88 | ** Special LogModule names are provided for controlling NSPR's log
|
---|
89 | ** service at execution time. These controls should be set in the
|
---|
90 | ** NSPR_LOG_MODULES environment variable at execution time to affect
|
---|
91 | ** NSPR's log service for your application.
|
---|
92 | **
|
---|
93 | ** The special LogModule "all" enables all LogModules. To enable all
|
---|
94 | ** LogModule calls to PR_LOG(), say:
|
---|
95 | **
|
---|
96 | ** set NSPR_LOG_MODULES=all:5
|
---|
97 | **
|
---|
98 | ** The special LogModule name "sync" tells the NSPR log service to do
|
---|
99 | ** unbuffered logging.
|
---|
100 | **
|
---|
101 | ** The special LogModule name "bufsize:<size>" tells NSPR to set the
|
---|
102 | ** log buffer to <size>.
|
---|
103 | **
|
---|
104 | ** The environment variable NSPR_LOG_FILE specifies the log file to use
|
---|
105 | ** unless the default of "stderr" is acceptable. For MS Windows
|
---|
106 | ** systems, NSPR_LOG_FILE can be set to a special value: "WinDebug"
|
---|
107 | ** (case sensitive). This value causes PR_LOG() output to be written
|
---|
108 | ** using the Windows API OutputDebugString(). OutputDebugString()
|
---|
109 | ** writes to the debugger window; some people find this helpful.
|
---|
110 | **
|
---|
111 | **
|
---|
112 | ** To put log messages in your programs, use the PR_LOG macro:
|
---|
113 | **
|
---|
114 | ** PR_LOG(<module>, <level>, (<printfString>, <args>*));
|
---|
115 | **
|
---|
116 | ** Where <module> is the address of a PRLogModuleInfo structure, and
|
---|
117 | ** <level> is one of the levels defined by the enumeration:
|
---|
118 | ** PRLogModuleLevel. <args> is a printf() style of argument list. That
|
---|
119 | ** is: (fmtstring, ...).
|
---|
120 | **
|
---|
121 | ** Example:
|
---|
122 | **
|
---|
123 | ** main() {
|
---|
124 | ** PRIntn one = 1;
|
---|
125 | ** PRLogModuleInfo * myLm = PR_NewLogModule("gizmo");
|
---|
126 | ** PR_LOG( myLm, PR_LOG_ALWAYS, ("Log this! %d\n", one));
|
---|
127 | ** return;
|
---|
128 | ** }
|
---|
129 | **
|
---|
130 | ** Note the use of printf() style arguments as the third agrument(s) to
|
---|
131 | ** PR_LOG().
|
---|
132 | **
|
---|
133 | ** After compiling and linking you application, set the environment:
|
---|
134 | **
|
---|
135 | ** set NSPR_LOG_MODULES=gizmo:5
|
---|
136 | ** set NSPR_LOG_FILE=logfile.txt
|
---|
137 | **
|
---|
138 | ** When you execute your application, the string "Log this! 1" will be
|
---|
139 | ** written to the file "logfile.txt".
|
---|
140 | **
|
---|
141 | ** Note to NSPR engineers: a number of PRLogModuleInfo structures are
|
---|
142 | ** defined and initialized in prinit.c. See this module for ideas on
|
---|
143 | ** what to log where.
|
---|
144 | **
|
---|
145 | */
|
---|
146 |
|
---|
147 | typedef enum PRLogModuleLevel {
|
---|
148 | PR_LOG_NONE = 0, /* nothing */
|
---|
149 | PR_LOG_ALWAYS = 1, /* always printed */
|
---|
150 | PR_LOG_ERROR = 2, /* error messages */
|
---|
151 | PR_LOG_WARNING = 3, /* warning messages */
|
---|
152 | PR_LOG_DEBUG = 4, /* debug messages */
|
---|
153 |
|
---|
154 | PR_LOG_NOTICE = PR_LOG_DEBUG, /* notice messages */
|
---|
155 | PR_LOG_WARN = PR_LOG_WARNING, /* warning messages */
|
---|
156 | PR_LOG_MIN = PR_LOG_DEBUG, /* minimal debugging messages */
|
---|
157 | PR_LOG_MAX = PR_LOG_DEBUG /* maximal debugging messages */
|
---|
158 | } PRLogModuleLevel;
|
---|
159 |
|
---|
160 | /*
|
---|
161 | ** One of these structures is created for each module that uses logging.
|
---|
162 | ** "name" is the name of the module
|
---|
163 | ** "level" is the debugging level selected for that module
|
---|
164 | */
|
---|
165 | typedef struct PRLogModuleInfo {
|
---|
166 | const char *name;
|
---|
167 | PRLogModuleLevel level;
|
---|
168 | struct PRLogModuleInfo *next;
|
---|
169 | } PRLogModuleInfo;
|
---|
170 |
|
---|
171 | /*
|
---|
172 | ** Create a new log module.
|
---|
173 | */
|
---|
174 | NSPR_API(PRLogModuleInfo*) PR_NewLogModule(const char *name);
|
---|
175 |
|
---|
176 | /*
|
---|
177 | ** Set the file to use for logging. Returns PR_FALSE if the file cannot
|
---|
178 | ** be created
|
---|
179 | */
|
---|
180 | NSPR_API(PRBool) PR_SetLogFile(const char *name);
|
---|
181 |
|
---|
182 | /*
|
---|
183 | ** Set the size of the logging buffer. If "buffer_size" is zero then the
|
---|
184 | ** logging becomes "synchronous" (or unbuffered).
|
---|
185 | */
|
---|
186 | NSPR_API(void) PR_SetLogBuffering(PRIntn buffer_size);
|
---|
187 |
|
---|
188 | /*
|
---|
189 | ** Print a string to the log. "fmt" is a PR_snprintf format type. All
|
---|
190 | ** messages printed to the log are preceeded by the name of the thread
|
---|
191 | ** and a time stamp. Also, the routine provides a missing newline if one
|
---|
192 | ** is not provided.
|
---|
193 | */
|
---|
194 | NSPR_API(void) PR_LogPrint(const char *fmt, ...);
|
---|
195 |
|
---|
196 | /*
|
---|
197 | ** Flush the log to its file.
|
---|
198 | */
|
---|
199 | NSPR_API(void) PR_LogFlush(void);
|
---|
200 |
|
---|
201 | /*
|
---|
202 | ** Windoze 16 can't support a large static string space for all of the
|
---|
203 | ** various debugging strings so logging is not enabled for it.
|
---|
204 | */
|
---|
205 | #if (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16)
|
---|
206 | #define PR_LOGGING 1
|
---|
207 |
|
---|
208 | #define PR_LOG_TEST(_module,_level) \
|
---|
209 | ((_module)->level >= (_level))
|
---|
210 |
|
---|
211 | /*
|
---|
212 | ** Log something.
|
---|
213 | ** "module" is the address of a PRLogModuleInfo structure
|
---|
214 | ** "level" is the desired logging level
|
---|
215 | ** "args" is a variable length list of arguments to print, in the following
|
---|
216 | ** format: ("printf style format string", ...)
|
---|
217 | */
|
---|
218 | #define PR_LOG(_module,_level,_args) \
|
---|
219 | PR_BEGIN_MACRO \
|
---|
220 | if (PR_LOG_TEST(_module,_level)) { \
|
---|
221 | PR_LogPrint _args; \
|
---|
222 | } \
|
---|
223 | PR_END_MACRO
|
---|
224 |
|
---|
225 | #else /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
|
---|
226 |
|
---|
227 | #undef PR_LOGGING
|
---|
228 | #define PR_LOG_TEST(module,level) 0
|
---|
229 | #define PR_LOG(module,level,args)
|
---|
230 |
|
---|
231 | #endif /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
|
---|
232 |
|
---|
233 | #ifndef NO_NSPR_10_SUPPORT
|
---|
234 |
|
---|
235 | #ifdef PR_LOGGING
|
---|
236 | #define PR_LOG_BEGIN PR_LOG
|
---|
237 | #define PR_LOG_END PR_LOG
|
---|
238 | #define PR_LOG_DEFINE PR_NewLogModule
|
---|
239 | #else
|
---|
240 | #define PR_LOG_BEGIN(module,level,args)
|
---|
241 | #define PR_LOG_END(module,level,args)
|
---|
242 | #define PR_LOG_DEFINE(_name) NULL
|
---|
243 | #endif /* PR_LOGGING */
|
---|
244 |
|
---|
245 | #endif /* NO_NSPR_10_SUPPORT */
|
---|
246 |
|
---|
247 | #if defined(DEBUG) || defined(FORCE_PR_ASSERT)
|
---|
248 |
|
---|
249 | NSPR_API(void) PR_Assert(const char *s, const char *file, PRIntn ln);
|
---|
250 | #define PR_ASSERT(_expr) \
|
---|
251 | ((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__))
|
---|
252 |
|
---|
253 | #define PR_NOT_REACHED(_reasonStr) \
|
---|
254 | PR_Assert(_reasonStr,__FILE__,__LINE__)
|
---|
255 |
|
---|
256 | #else
|
---|
257 |
|
---|
258 | #define PR_ASSERT(expr) ((void) 0)
|
---|
259 | #define PR_NOT_REACHED(reasonStr)
|
---|
260 |
|
---|
261 | #endif /* defined(DEBUG) || defined(FORCE_PR_ASSERT) */
|
---|
262 |
|
---|
263 | PR_END_EXTERN_C
|
---|
264 |
|
---|
265 | #endif /* prlog_h___ */
|
---|