1 | /** @file
|
---|
2 | * IPRT - Logging.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_log_h
|
---|
27 | #define ___iprt_log_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/stdarg.h>
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_log RTLog - Logging
|
---|
36 | * @ingroup grp_rt
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * IPRT Logging Groups.
|
---|
42 | * (Remember to update RT_LOGGROUP_NAMES!)
|
---|
43 | *
|
---|
44 | * @remark It should be pretty obvious, but just to have
|
---|
45 | * mentioned it, the values are sorted alphabetically (using the
|
---|
46 | * english alphabet) except for _DEFAULT which is always first.
|
---|
47 | *
|
---|
48 | * If anyone might be wondering what the alphabet looks like:
|
---|
49 | * a b c d e f g h i j k l m n o p q r s t u v w x y z
|
---|
50 | */
|
---|
51 | typedef enum RTLOGGROUP
|
---|
52 | {
|
---|
53 | /** Default logging group. */
|
---|
54 | RTLOGGROUP_DEFAULT,
|
---|
55 | RTLOGGROUP_DIR,
|
---|
56 | RTLOGGROUP_FILE,
|
---|
57 | RTLOGGROUP_FS,
|
---|
58 | RTLOGGROUP_LDR,
|
---|
59 | RTLOGGROUP_PATH,
|
---|
60 | RTLOGGROUP_PROCESS,
|
---|
61 | RTLOGGROUP_THREAD,
|
---|
62 | RTLOGGROUP_TIME,
|
---|
63 | RTLOGGROUP_TIMER,
|
---|
64 | RTLOGGROUP_ZIP = 31,
|
---|
65 | RTLOGGROUP_FIRST_USER = 32
|
---|
66 | } RTLOGGROUP;
|
---|
67 |
|
---|
68 | /** @def RT_LOGGROUP_NAMES
|
---|
69 | * IPRT Logging group names.
|
---|
70 | *
|
---|
71 | * Must correspond 100% to RTLOGGROUP!
|
---|
72 | * Don't forget commas!
|
---|
73 | *
|
---|
74 | * @remark It should be pretty obvious, but just to have
|
---|
75 | * mentioned it, the values are sorted alphabetically (using the
|
---|
76 | * english alphabet) except for _DEFAULT which is always first.
|
---|
77 | *
|
---|
78 | * If anyone might be wondering what the alphabet looks like:
|
---|
79 | * a b c d e f g h i j k l m n o p q r s t u v w x y z
|
---|
80 | */
|
---|
81 | #define RT_LOGGROUP_NAMES \
|
---|
82 | "DEFAULT", \
|
---|
83 | "RT_DIR", \
|
---|
84 | "RT_FILE", \
|
---|
85 | "RT_FS", \
|
---|
86 | "RT_LDR", \
|
---|
87 | "RT_PATH", \
|
---|
88 | "RT_PROCESS", \
|
---|
89 | "RT_THREAD", \
|
---|
90 | "RT_TIME", \
|
---|
91 | "RT_TIMER", \
|
---|
92 | "RT_10", \
|
---|
93 | "RT_11", \
|
---|
94 | "RT_12", \
|
---|
95 | "RT_13", \
|
---|
96 | "RT_14", \
|
---|
97 | "RT_15", \
|
---|
98 | "RT_16", \
|
---|
99 | "RT_17", \
|
---|
100 | "RT_18", \
|
---|
101 | "RT_19", \
|
---|
102 | "RT_20", \
|
---|
103 | "RT_21", \
|
---|
104 | "RT_22", \
|
---|
105 | "RT_23", \
|
---|
106 | "RT_24", \
|
---|
107 | "RT_25", \
|
---|
108 | "RT_26", \
|
---|
109 | "RT_27", \
|
---|
110 | "RT_28", \
|
---|
111 | "RT_29", \
|
---|
112 | "RT_30", \
|
---|
113 | "RT_ZIP" \
|
---|
114 |
|
---|
115 |
|
---|
116 | /** @def LOG_GROUP
|
---|
117 | * Active logging group.
|
---|
118 | */
|
---|
119 | #ifndef LOG_GROUP
|
---|
120 | # define LOG_GROUP RTLOGGROUP_DEFAULT
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | /** @def LOG_INSTANCE
|
---|
124 | * Active logging instance.
|
---|
125 | */
|
---|
126 | #ifndef LOG_INSTANCE
|
---|
127 | # define LOG_INSTANCE NULL
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | /** @def LOG_REL_INSTANCE
|
---|
131 | * Active release logging instance.
|
---|
132 | */
|
---|
133 | #ifndef LOG_REL_INSTANCE
|
---|
134 | # define LOG_REL_INSTANCE NULL
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | /** @def LOG_FN_FMT
|
---|
138 | * You can use this to specify you desired way of printing __PRETTY_FUNCTION__
|
---|
139 | * if you dislike the default one.
|
---|
140 | */
|
---|
141 | #ifndef LOG_FN_FMT
|
---|
142 | # define LOG_FN_FMT "%Rfn"
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | /** Logger structure. */
|
---|
146 | #ifdef IN_RC
|
---|
147 | typedef struct RTLOGGERRC RTLOGGER;
|
---|
148 | #else
|
---|
149 | typedef struct RTLOGGER RTLOGGER;
|
---|
150 | #endif
|
---|
151 | /** Pointer to logger structure. */
|
---|
152 | typedef RTLOGGER *PRTLOGGER;
|
---|
153 | /** Pointer to const logger structure. */
|
---|
154 | typedef const RTLOGGER *PCRTLOGGER;
|
---|
155 |
|
---|
156 |
|
---|
157 | /** Guest context logger structure. */
|
---|
158 | typedef struct RTLOGGERRC RTLOGGERRC;
|
---|
159 | /** Pointer to guest context logger structure. */
|
---|
160 | typedef RTLOGGERRC *PRTLOGGERRC;
|
---|
161 | /** Pointer to const guest context logger structure. */
|
---|
162 | typedef const RTLOGGERRC *PCRTLOGGERRC;
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Logger function.
|
---|
167 | *
|
---|
168 | * @param pszFormat Format string.
|
---|
169 | * @param ... Optional arguments as specified in the format string.
|
---|
170 | */
|
---|
171 | typedef DECLCALLBACK(void) FNRTLOGGER(const char *pszFormat, ...);
|
---|
172 | /** Pointer to logger function. */
|
---|
173 | typedef FNRTLOGGER *PFNRTLOGGER;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Flush function.
|
---|
177 | *
|
---|
178 | * @param pLogger Pointer to the logger instance which is to be flushed.
|
---|
179 | */
|
---|
180 | typedef DECLCALLBACK(void) FNRTLOGFLUSH(PRTLOGGER pLogger);
|
---|
181 | /** Pointer to flush function. */
|
---|
182 | typedef FNRTLOGFLUSH *PFNRTLOGFLUSH;
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Flush function.
|
---|
186 | *
|
---|
187 | * @param pLogger Pointer to the logger instance which is to be flushed.
|
---|
188 | */
|
---|
189 | typedef DECLCALLBACK(void) FNRTLOGFLUSHGC(PRTLOGGERRC pLogger);
|
---|
190 | /** Pointer to logger function. */
|
---|
191 | typedef RCPTRTYPE(FNRTLOGFLUSHGC *) PFNRTLOGFLUSHGC;
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Custom log prefix callback.
|
---|
195 | *
|
---|
196 | *
|
---|
197 | * @returns The number of chars written.
|
---|
198 | *
|
---|
199 | * @param pLogger Pointer to the logger instance.
|
---|
200 | * @param pchBuf Output buffer pointer.
|
---|
201 | * No need to terminate the output.
|
---|
202 | * @param cchBuf The size of the output buffer.
|
---|
203 | * @param pvUser The user argument.
|
---|
204 | */
|
---|
205 | typedef DECLCALLBACK(size_t) FNRTLOGPREFIX(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
|
---|
206 | /** Pointer to prefix callback function. */
|
---|
207 | typedef FNRTLOGPREFIX *PFNRTLOGPREFIX;
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Logger instance structure for GC.
|
---|
213 | */
|
---|
214 | struct RTLOGGERRC
|
---|
215 | {
|
---|
216 | /** Pointer to temporary scratch buffer.
|
---|
217 | * This is used to format the log messages. */
|
---|
218 | char achScratch[32768];
|
---|
219 | /** Current scratch buffer position. */
|
---|
220 | uint32_t offScratch;
|
---|
221 | /** This is set if a prefix is pending. */
|
---|
222 | uint32_t fPendingPrefix;
|
---|
223 | /** Pointer to the logger function.
|
---|
224 | * This is actually pointer to a wrapper which will push a pointer to the
|
---|
225 | * instance pointer onto the stack before jumping to the real logger function.
|
---|
226 | * A very unfortunate hack to work around the missing variadic macro support in C++. */
|
---|
227 | RCPTRTYPE(PFNRTLOGGER) pfnLogger;
|
---|
228 | /** Pointer to the flush function. */
|
---|
229 | PFNRTLOGFLUSHGC pfnFlush;
|
---|
230 | /** Magic number (RTLOGGERRC_MAGIC). */
|
---|
231 | uint32_t u32Magic;
|
---|
232 | /** Logger instance flags - RTLOGFLAGS. */
|
---|
233 | uint32_t fFlags;
|
---|
234 | /** Number of groups in the afGroups member. */
|
---|
235 | uint32_t cGroups;
|
---|
236 | /** Group flags array - RTLOGGRPFLAGS.
|
---|
237 | * This member have variable length and may extend way beyond
|
---|
238 | * the declared size of 1 entry. */
|
---|
239 | uint32_t afGroups[1];
|
---|
240 | };
|
---|
241 |
|
---|
242 | /** RTLOGGERRC::u32Magic value. (John Rogers Searle) */
|
---|
243 | #define RTLOGGERRC_MAGIC 0x19320731
|
---|
244 |
|
---|
245 |
|
---|
246 |
|
---|
247 | #ifndef IN_RC
|
---|
248 | /**
|
---|
249 | * Logger instance structure.
|
---|
250 | */
|
---|
251 | struct RTLOGGER
|
---|
252 | {
|
---|
253 | /** Pointer to temporary scratch buffer.
|
---|
254 | * This is used to format the log messages. */
|
---|
255 | char achScratch[32768];
|
---|
256 | /** Current scratch buffer position. */
|
---|
257 | uint32_t offScratch;
|
---|
258 | /** This is set if a prefix is pending. */
|
---|
259 | uint32_t fPendingPrefix;
|
---|
260 | /** Pointer to the logger function.
|
---|
261 | * This is actually pointer to a wrapper which will push a pointer to the
|
---|
262 | * instance pointer onto the stack before jumping to the real logger function.
|
---|
263 | * A very unfortunate hack to work around the missing variadic macro support in C++.
|
---|
264 | * (The memory is (not R0) allocated using RTMemExecAlloc().) */
|
---|
265 | PFNRTLOGGER pfnLogger;
|
---|
266 | /** Pointer to the flush function. */
|
---|
267 | PFNRTLOGFLUSH pfnFlush;
|
---|
268 | /** Custom prefix callback. */
|
---|
269 | PFNRTLOGPREFIX pfnPrefix;
|
---|
270 | /** Prefix callback argument. */
|
---|
271 | void *pvPrefixUserArg;
|
---|
272 | /** Spinning mutex semaphore. */
|
---|
273 | RTSEMSPINMUTEX hSpinMtx;
|
---|
274 | /** Magic number. */
|
---|
275 | uint32_t u32Magic;
|
---|
276 | /** Logger instance flags - RTLOGFLAGS. */
|
---|
277 | uint32_t fFlags;
|
---|
278 | /** Destination flags - RTLOGDEST. */
|
---|
279 | uint32_t fDestFlags;
|
---|
280 | /** Handle to log file (if open). */
|
---|
281 | RTFILE File;
|
---|
282 | /** Pointer to filename.
|
---|
283 | * (The memory is allocated in the same block as RTLOGGER.) */
|
---|
284 | char *pszFilename;
|
---|
285 | /** Pointer to the group name array.
|
---|
286 | * (The data is readonly and provided by the user.) */
|
---|
287 | const char * const *papszGroups;
|
---|
288 | /** The max number of groups that there is room for in afGroups and papszGroups.
|
---|
289 | * Used by RTLogCopyGroupAndFlags(). */
|
---|
290 | uint32_t cMaxGroups;
|
---|
291 | /** Number of groups in the afGroups and papszGroups members. */
|
---|
292 | uint32_t cGroups;
|
---|
293 | /** Group flags array - RTLOGGRPFLAGS.
|
---|
294 | * This member have variable length and may extend way beyond
|
---|
295 | * the declared size of 1 entry. */
|
---|
296 | uint32_t afGroups[1];
|
---|
297 | };
|
---|
298 |
|
---|
299 | /** RTLOGGER::u32Magic value. (Avram Noam Chomsky) */
|
---|
300 | #define RTLOGGER_MAGIC 0x19281207
|
---|
301 |
|
---|
302 | #endif /* !IN_RC */
|
---|
303 |
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Logger flags.
|
---|
307 | */
|
---|
308 | typedef enum RTLOGFLAGS
|
---|
309 | {
|
---|
310 | /** The logger instance is disabled for normal output. */
|
---|
311 | RTLOGFLAGS_DISABLED = 0x00000001,
|
---|
312 | /** The logger instance is using buffered output. */
|
---|
313 | RTLOGFLAGS_BUFFERED = 0x00000002,
|
---|
314 | /** The logger instance expands LF to CR/LF. */
|
---|
315 | RTLOGFLAGS_USECRLF = 0x00000010,
|
---|
316 | /** Append to the log destination where applicable. */
|
---|
317 | RTLOGFLAGS_APPEND = 0x00000020,
|
---|
318 | /** Show relative timestamps with PREFIX_TSC and PREFIX_TS */
|
---|
319 | RTLOGFLAGS_REL_TS = 0x00000040,
|
---|
320 | /** Show decimal timestamps with PREFIX_TSC and PREFIX_TS */
|
---|
321 | RTLOGFLAGS_DECIMAL_TS = 0x00000080,
|
---|
322 | /** Open the file in write through mode. */
|
---|
323 | RTLOGFLAGS_WRITE_THROUGH = 0x00000100,
|
---|
324 | /** Flush the file to disk when flushing the buffer. */
|
---|
325 | RTLOGFLAGS_FLUSH = 0x00000200,
|
---|
326 | /** New lines should be prefixed with the write and read lock counts. */
|
---|
327 | RTLOGFLAGS_PREFIX_LOCK_COUNTS = 0x00008000,
|
---|
328 | /** New lines should be prefixed with the CPU id (ApicID on intel/amd). */
|
---|
329 | RTLOGFLAGS_PREFIX_CPUID = 0x00010000,
|
---|
330 | /** New lines should be prefixed with the native process id. */
|
---|
331 | RTLOGFLAGS_PREFIX_PID = 0x00020000,
|
---|
332 | /** New lines should be prefixed with group flag number causing the output. */
|
---|
333 | RTLOGFLAGS_PREFIX_FLAG_NO = 0x00040000,
|
---|
334 | /** New lines should be prefixed with group flag name causing the output. */
|
---|
335 | RTLOGFLAGS_PREFIX_FLAG = 0x00080000,
|
---|
336 | /** New lines should be prefixed with group number. */
|
---|
337 | RTLOGFLAGS_PREFIX_GROUP_NO = 0x00100000,
|
---|
338 | /** New lines should be prefixed with group name. */
|
---|
339 | RTLOGFLAGS_PREFIX_GROUP = 0x00200000,
|
---|
340 | /** New lines should be prefixed with the native thread id. */
|
---|
341 | RTLOGFLAGS_PREFIX_TID = 0x00400000,
|
---|
342 | /** New lines should be prefixed with thread name. */
|
---|
343 | RTLOGFLAGS_PREFIX_THREAD = 0x00800000,
|
---|
344 | /** New lines should be prefixed with data from a custom callback. */
|
---|
345 | RTLOGFLAGS_PREFIX_CUSTOM = 0x01000000,
|
---|
346 | /** New lines should be prefixed with formatted timestamp since program start. */
|
---|
347 | RTLOGFLAGS_PREFIX_TIME_PROG = 0x04000000,
|
---|
348 | /** New lines should be prefixed with formatted timestamp (UCT). */
|
---|
349 | RTLOGFLAGS_PREFIX_TIME = 0x08000000,
|
---|
350 | /** New lines should be prefixed with milliseconds since program start. */
|
---|
351 | RTLOGFLAGS_PREFIX_MS_PROG = 0x10000000,
|
---|
352 | /** New lines should be prefixed with timestamp. */
|
---|
353 | RTLOGFLAGS_PREFIX_TSC = 0x20000000,
|
---|
354 | /** New lines should be prefixed with timestamp. */
|
---|
355 | RTLOGFLAGS_PREFIX_TS = 0x40000000,
|
---|
356 | /** The prefix mask. */
|
---|
357 | RTLOGFLAGS_PREFIX_MASK = 0x7dff8000
|
---|
358 | } RTLOGFLAGS;
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Logger per group flags.
|
---|
362 | */
|
---|
363 | typedef enum RTLOGGRPFLAGS
|
---|
364 | {
|
---|
365 | /** Enabled. */
|
---|
366 | RTLOGGRPFLAGS_ENABLED = 0x00000001,
|
---|
367 | /** Level 1 logging. */
|
---|
368 | RTLOGGRPFLAGS_LEVEL_1 = 0x00000002,
|
---|
369 | /** Level 2 logging. */
|
---|
370 | RTLOGGRPFLAGS_LEVEL_2 = 0x00000004,
|
---|
371 | /** Level 3 logging. */
|
---|
372 | RTLOGGRPFLAGS_LEVEL_3 = 0x00000008,
|
---|
373 | /** Level 4 logging. */
|
---|
374 | RTLOGGRPFLAGS_LEVEL_4 = 0x00000010,
|
---|
375 | /** Level 5 logging. */
|
---|
376 | RTLOGGRPFLAGS_LEVEL_5 = 0x00000020,
|
---|
377 | /** Level 6 logging. */
|
---|
378 | RTLOGGRPFLAGS_LEVEL_6 = 0x00000040,
|
---|
379 | /** Flow logging. */
|
---|
380 | RTLOGGRPFLAGS_FLOW = 0x00000080,
|
---|
381 |
|
---|
382 | /** Lelik logging. */
|
---|
383 | RTLOGGRPFLAGS_LELIK = 0x00000100,
|
---|
384 | /** Michael logging. */
|
---|
385 | RTLOGGRPFLAGS_MICHAEL = 0x00000200,
|
---|
386 | /** dmik logging. */
|
---|
387 | RTLOGGRPFLAGS_DMIK = 0x00000400,
|
---|
388 | /** sunlover logging. */
|
---|
389 | RTLOGGRPFLAGS_SUNLOVER = 0x00000800,
|
---|
390 | /** Achim logging. */
|
---|
391 | RTLOGGRPFLAGS_ACHIM = 0x00001000,
|
---|
392 | /** Sander logging. */
|
---|
393 | RTLOGGRPFLAGS_SANDER = 0x00002000,
|
---|
394 | /** Klaus logging. */
|
---|
395 | RTLOGGRPFLAGS_KLAUS = 0x00004000,
|
---|
396 | /** Frank logging. */
|
---|
397 | RTLOGGRPFLAGS_FRANK = 0x00008000,
|
---|
398 | /** bird logging. */
|
---|
399 | RTLOGGRPFLAGS_BIRD = 0x00010000,
|
---|
400 | /** aleksey logging. */
|
---|
401 | RTLOGGRPFLAGS_ALEKSEY = 0x00020000,
|
---|
402 | /** dj logging. */
|
---|
403 | RTLOGGRPFLAGS_DJ = 0x00040000,
|
---|
404 | /** NoName logging. */
|
---|
405 | RTLOGGRPFLAGS_NONAME = 0x00080000
|
---|
406 | } RTLOGGRPFLAGS;
|
---|
407 |
|
---|
408 | /**
|
---|
409 | * Logger destination type.
|
---|
410 | */
|
---|
411 | typedef enum RTLOGDEST
|
---|
412 | {
|
---|
413 | /** Log to file. */
|
---|
414 | RTLOGDEST_FILE = 0x00000001,
|
---|
415 | /** Log to stdout. */
|
---|
416 | RTLOGDEST_STDOUT = 0x00000002,
|
---|
417 | /** Log to stderr. */
|
---|
418 | RTLOGDEST_STDERR = 0x00000004,
|
---|
419 | /** Log to debugger (win32 only). */
|
---|
420 | RTLOGDEST_DEBUGGER = 0x00000008,
|
---|
421 | /** Log to com port. */
|
---|
422 | RTLOGDEST_COM = 0x00000010,
|
---|
423 | /** Just a dummy flag to be used when no other flag applies. */
|
---|
424 | RTLOGDEST_DUMMY = 0x20000000,
|
---|
425 | /** Log to a user defined output stream. */
|
---|
426 | RTLOGDEST_USER = 0x40000000
|
---|
427 | } RTLOGDEST;
|
---|
428 |
|
---|
429 |
|
---|
430 | RTDECL(void) RTLogPrintfEx(void *pvInstance, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
|
---|
431 |
|
---|
432 |
|
---|
433 | #ifdef DOXYGEN_RUNNING
|
---|
434 | # define LOG_DISABLED
|
---|
435 | # define LOG_ENABLED
|
---|
436 | # define LOG_ENABLE_FLOW
|
---|
437 | #endif
|
---|
438 |
|
---|
439 | /** @def LOG_DISABLED
|
---|
440 | * Use this compile time define to disable all logging macros. It can
|
---|
441 | * be overriden for each of the logging macros by the LOG_ENABLE*
|
---|
442 | * compile time defines.
|
---|
443 | */
|
---|
444 |
|
---|
445 | /** @def LOG_ENABLED
|
---|
446 | * Use this compile time define to enable logging when not in debug mode
|
---|
447 | * or LOG_DISABLED is set.
|
---|
448 | * This will enabled Log() only.
|
---|
449 | */
|
---|
450 |
|
---|
451 | /** @def LOG_ENABLE_FLOW
|
---|
452 | * Use this compile time define to enable flow logging when not in
|
---|
453 | * debug mode or LOG_DISABLED is defined.
|
---|
454 | * This will enable LogFlow() only.
|
---|
455 | */
|
---|
456 |
|
---|
457 | /*
|
---|
458 | * Determin whether logging is enabled and forcefully normalize the indicators.
|
---|
459 | */
|
---|
460 | #if (defined(DEBUG) || defined(LOG_ENABLED)) && !defined(LOG_DISABLED)
|
---|
461 | # undef LOG_DISABLED
|
---|
462 | # undef LOG_ENABLED
|
---|
463 | # define LOG_ENABLED
|
---|
464 | #else
|
---|
465 | # undef LOG_ENABLED
|
---|
466 | # undef LOG_DISABLED
|
---|
467 | # define LOG_DISABLED
|
---|
468 | #endif
|
---|
469 |
|
---|
470 |
|
---|
471 | /** @def LOG_USE_C99
|
---|
472 | * Governs the use of variadic macros.
|
---|
473 | */
|
---|
474 | #ifndef LOG_USE_C99
|
---|
475 | # if defined(RT_ARCH_AMD64) || defined(RT_OS_DARWIN) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
|
---|
476 | # define LOG_USE_C99
|
---|
477 | # endif
|
---|
478 | #endif
|
---|
479 |
|
---|
480 |
|
---|
481 | /** @def LogIt
|
---|
482 | * Write to specific logger if group enabled.
|
---|
483 | */
|
---|
484 | #ifdef LOG_ENABLED
|
---|
485 | # if defined(LOG_USE_C99)
|
---|
486 | # define _LogRemoveParentheseis(...) __VA_ARGS__
|
---|
487 | # define _LogIt(pvInst, fFlags, iGroup, ...) RTLogLoggerEx((PRTLOGGER)pvInst, fFlags, iGroup, __VA_ARGS__)
|
---|
488 | # define LogIt(pvInst, fFlags, iGroup, fmtargs) _LogIt(pvInst, fFlags, iGroup, _LogRemoveParentheseis fmtargs)
|
---|
489 | # define _LogItAlways(pvInst, fFlags, iGroup, ...) RTLogLoggerEx((PRTLOGGER)pvInst, fFlags, ~0U, __VA_ARGS__)
|
---|
490 | # define LogItAlways(pvInst, fFlags, iGroup, fmtargs) _LogItAlways(pvInst, fFlags, iGroup, _LogRemoveParentheseis fmtargs)
|
---|
491 | /** @todo invent a flag or something for skipping the group check so we can pass iGroup. LogItAlways. */
|
---|
492 | # else
|
---|
493 | # define LogIt(pvInst, fFlags, iGroup, fmtargs) \
|
---|
494 | do \
|
---|
495 | { \
|
---|
496 | register PRTLOGGER LogIt_pLogger = (PRTLOGGER)(pvInst) ? (PRTLOGGER)(pvInst) : RTLogDefaultInstance(); \
|
---|
497 | if (LogIt_pLogger) \
|
---|
498 | { \
|
---|
499 | register unsigned LogIt_fFlags = LogIt_pLogger->afGroups[(unsigned)(iGroup) < LogIt_pLogger->cGroups ? (unsigned)(iGroup) : 0]; \
|
---|
500 | if ((LogIt_fFlags & ((fFlags) | RTLOGGRPFLAGS_ENABLED)) == ((fFlags) | RTLOGGRPFLAGS_ENABLED)) \
|
---|
501 | LogIt_pLogger->pfnLogger fmtargs; \
|
---|
502 | } \
|
---|
503 | } while (0)
|
---|
504 | # define LogItAlways(pvInst, fFlags, iGroup, fmtargs) \
|
---|
505 | do \
|
---|
506 | { \
|
---|
507 | register PRTLOGGER LogIt_pLogger = (PRTLOGGER)(pvInst) ? (PRTLOGGER)(pvInst) : RTLogDefaultInstance(); \
|
---|
508 | if (LogIt_pLogger) \
|
---|
509 | LogIt_pLogger->pfnLogger fmtargs; \
|
---|
510 | } while (0)
|
---|
511 | # endif
|
---|
512 | #else
|
---|
513 | # define LogIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
|
---|
514 | # define LogItAlways(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
|
---|
515 | # if defined(LOG_USE_C99)
|
---|
516 | # define _LogRemoveParentheseis(...) __VA_ARGS__
|
---|
517 | # define _LogIt(pvInst, fFlags, iGroup, ...) do { } while (0)
|
---|
518 | # define _LogItAlways(pvInst, fFlags, iGroup, ...) do { } while (0)
|
---|
519 | # endif
|
---|
520 | #endif
|
---|
521 |
|
---|
522 |
|
---|
523 | /** @def Log
|
---|
524 | * Level 1 logging that works regardless of the group settings.
|
---|
525 | */
|
---|
526 | #define LogAlways(a) LogItAlways(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
|
---|
527 |
|
---|
528 | /** @def Log
|
---|
529 | * Level 1 logging.
|
---|
530 | */
|
---|
531 | #define Log(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
|
---|
532 |
|
---|
533 | /** @def Log2
|
---|
534 | * Level 2 logging.
|
---|
535 | */
|
---|
536 | #define Log2(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, a)
|
---|
537 |
|
---|
538 | /** @def Log3
|
---|
539 | * Level 3 logging.
|
---|
540 | */
|
---|
541 | #define Log3(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, a)
|
---|
542 |
|
---|
543 | /** @def Log4
|
---|
544 | * Level 4 logging.
|
---|
545 | */
|
---|
546 | #define Log4(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, a)
|
---|
547 |
|
---|
548 | /** @def Log5
|
---|
549 | * Level 5 logging.
|
---|
550 | */
|
---|
551 | #define Log5(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, a)
|
---|
552 |
|
---|
553 | /** @def Log6
|
---|
554 | * Level 6 logging.
|
---|
555 | */
|
---|
556 | #define Log6(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, a)
|
---|
557 |
|
---|
558 | /** @def LogFlow
|
---|
559 | * Logging of execution flow.
|
---|
560 | */
|
---|
561 | #define LogFlow(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, a)
|
---|
562 |
|
---|
563 | /** @def LogLelik
|
---|
564 | * lelik logging.
|
---|
565 | */
|
---|
566 | #define LogLelik(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LELIK, LOG_GROUP, a)
|
---|
567 |
|
---|
568 |
|
---|
569 | /** @def LogMichael
|
---|
570 | * michael logging.
|
---|
571 | */
|
---|
572 | #define LogMichael(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_MICHAEL, LOG_GROUP, a)
|
---|
573 |
|
---|
574 | /** @def LogDmik
|
---|
575 | * dmik logging.
|
---|
576 | */
|
---|
577 | #define LogDmik(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_DMIK, LOG_GROUP, a)
|
---|
578 |
|
---|
579 | /** @def LogSunlover
|
---|
580 | * sunlover logging.
|
---|
581 | */
|
---|
582 | #define LogSunlover(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_SUNLOVER, LOG_GROUP, a)
|
---|
583 |
|
---|
584 | /** @def LogAchim
|
---|
585 | * Achim logging.
|
---|
586 | */
|
---|
587 | #define LogAchim(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_ACHIM, LOG_GROUP, a)
|
---|
588 |
|
---|
589 | /** @def LogSander
|
---|
590 | * Sander logging.
|
---|
591 | */
|
---|
592 | #define LogSander(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_SANDER, LOG_GROUP, a)
|
---|
593 |
|
---|
594 | /** @def LogKlaus
|
---|
595 | * klaus logging.
|
---|
596 | */
|
---|
597 | #define LogKlaus(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_KLAUS, LOG_GROUP, a)
|
---|
598 |
|
---|
599 | /** @def LogFrank
|
---|
600 | * frank logging.
|
---|
601 | */
|
---|
602 | #define LogFrank(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FRANK, LOG_GROUP, a)
|
---|
603 |
|
---|
604 | /** @def LogBird
|
---|
605 | * bird logging.
|
---|
606 | */
|
---|
607 | #define LogBird(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_BIRD, LOG_GROUP, a)
|
---|
608 |
|
---|
609 | /** @def LogAleksey
|
---|
610 | * aleksey logging.
|
---|
611 | */
|
---|
612 | #define LogAleksey(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_ALEKSEY, LOG_GROUP, a)
|
---|
613 |
|
---|
614 | /** @def LogDJ
|
---|
615 | * dj logging.
|
---|
616 | */
|
---|
617 | #define LogDJ(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_DJ, LOG_GROUP, a)
|
---|
618 |
|
---|
619 | /** @def LogNoName
|
---|
620 | * NoName logging.
|
---|
621 | */
|
---|
622 | #define LogNoName(a) LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_NONAME, LOG_GROUP, a)
|
---|
623 |
|
---|
624 | /** @def LogWarning
|
---|
625 | * The same as Log(), but prepents a <tt>"WARNING! "</tt> string to the message.
|
---|
626 | *
|
---|
627 | * @param a Custom log message in format <tt>("string\n" [, args])</tt>.
|
---|
628 | */
|
---|
629 | #if defined(LOG_USE_C99)
|
---|
630 | # define LogWarning(a) \
|
---|
631 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "WARNING! %M", _LogRemoveParentheseis a )
|
---|
632 | #else
|
---|
633 | # define LogWarning(a) \
|
---|
634 | do { Log(("WARNING! ")); Log(a); } while (0)
|
---|
635 | #endif
|
---|
636 |
|
---|
637 | /** @def LogTrace
|
---|
638 | * Macro to trace the execution flow: logs the file name, line number and
|
---|
639 | * function name. Can be easily searched for in log files using the
|
---|
640 | * ">>>>>" pattern (prepended to the beginning of each line).
|
---|
641 | */
|
---|
642 | #define LogTrace() \
|
---|
643 | LogFlow((">>>>> %s (%d): " LOG_FN_FMT "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
---|
644 |
|
---|
645 | /** @def LogTraceMsg
|
---|
646 | * The same as LogTrace but logs a custom log message right after the trace line.
|
---|
647 | *
|
---|
648 | * @param a Custom log message in format <tt>("string\n" [, args])</tt>.
|
---|
649 | */
|
---|
650 | #ifdef LOG_USE_C99
|
---|
651 | # define LogTraceMsg(a) \
|
---|
652 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, ">>>>> %s (%d): " LOG_FN_FMT ": %M", __FILE__, __LINE__, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
653 | #else
|
---|
654 | # define LogTraceMsg(a) \
|
---|
655 | do { LogFlow((">>>>> %s (%d): " LOG_FN_FMT ": ", __FILE__, __LINE__, __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
|
---|
656 | #endif
|
---|
657 |
|
---|
658 | /** @def LogFunc
|
---|
659 | * Level 1 logging inside C/C++ functions.
|
---|
660 | *
|
---|
661 | * Prepends the given log message with the function name followed by a
|
---|
662 | * semicolon and space.
|
---|
663 | *
|
---|
664 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
665 | */
|
---|
666 | #ifdef LOG_USE_C99
|
---|
667 | # define LogFunc(a) \
|
---|
668 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
669 | #else
|
---|
670 | # define LogFunc(a) \
|
---|
671 | do { Log((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log(a); } while (0)
|
---|
672 | #endif
|
---|
673 |
|
---|
674 | /** @def LogThisFunc
|
---|
675 | * The same as LogFunc but for class functions (methods): the resulting log
|
---|
676 | * line is additionally prepended with a hex value of |this| pointer.
|
---|
677 | *
|
---|
678 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
679 | */
|
---|
680 | #ifdef LOG_USE_C99
|
---|
681 | # define LogThisFunc(a) \
|
---|
682 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
683 | #else
|
---|
684 | # define LogThisFunc(a) \
|
---|
685 | do { Log(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log(a); } while (0)
|
---|
686 | #endif
|
---|
687 |
|
---|
688 | /** @def LogFlowFunc
|
---|
689 | * Macro to log the execution flow inside C/C++ functions.
|
---|
690 | *
|
---|
691 | * Prepends the given log message with the function name followed by
|
---|
692 | * a semicolon and space.
|
---|
693 | *
|
---|
694 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
695 | */
|
---|
696 | #ifdef LOG_USE_C99
|
---|
697 | # define LogFlowFunc(a) \
|
---|
698 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
699 | #else
|
---|
700 | # define LogFlowFunc(a) \
|
---|
701 | do { LogFlow((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
|
---|
702 | #endif
|
---|
703 |
|
---|
704 | /** @def LogWarningFunc
|
---|
705 | * The same as LogWarning(), but prepents the log message with the function name.
|
---|
706 | *
|
---|
707 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
708 | */
|
---|
709 | #ifdef LOG_USE_C99
|
---|
710 | # define LogWarningFunc(a) \
|
---|
711 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": WARNING! %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
712 | #else
|
---|
713 | # define LogWarningFunc(a) \
|
---|
714 | do { Log((LOG_FN_FMT ": WARNING! ", __PRETTY_FUNCTION__)); Log(a); } while (0)
|
---|
715 | #endif
|
---|
716 |
|
---|
717 | /** @def LogFlowThisFunc
|
---|
718 | * The same as LogFlowFunc but for class functions (methods): the resulting log
|
---|
719 | * line is additionally prepended with a hex value of |this| pointer.
|
---|
720 | *
|
---|
721 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
722 | */
|
---|
723 | #ifdef LOG_USE_C99
|
---|
724 | # define LogFlowThisFunc(a) \
|
---|
725 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
726 | #else
|
---|
727 | # define LogFlowThisFunc(a) \
|
---|
728 | do { LogFlow(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
|
---|
729 | #endif
|
---|
730 |
|
---|
731 | /** @def LogWarningThisFunc
|
---|
732 | * The same as LogWarningFunc() but for class functions (methods): the resulting
|
---|
733 | * log line is additionally prepended with a hex value of |this| pointer.
|
---|
734 | *
|
---|
735 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
736 | */
|
---|
737 | #ifdef LOG_USE_C99
|
---|
738 | # define LogWarningThisFunc(a) \
|
---|
739 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": WARNING! %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
740 | #else
|
---|
741 | # define LogWarningThisFunc(a) \
|
---|
742 | do { Log(("{%p} " LOG_FN_FMT ": WARNING! ", this, __PRETTY_FUNCTION__)); Log(a); } while (0)
|
---|
743 | #endif
|
---|
744 |
|
---|
745 | /** Shortcut to |LogFlowFunc ("ENTER\n")|, marks the beginnig of the function. */
|
---|
746 | #define LogFlowFuncEnter() LogFlowFunc(("ENTER\n"))
|
---|
747 |
|
---|
748 | /** Shortcut to |LogFlowFunc ("LEAVE\n")|, marks the end of the function. */
|
---|
749 | #define LogFlowFuncLeave() LogFlowFunc(("LEAVE\n"))
|
---|
750 |
|
---|
751 | /** Shortcut to |LogFlowThisFunc ("ENTER\n")|, marks the beginnig of the function. */
|
---|
752 | #define LogFlowThisFuncEnter() LogFlowThisFunc(("ENTER\n"))
|
---|
753 |
|
---|
754 | /** Shortcut to |LogFlowThisFunc ("LEAVE\n")|, marks the end of the function. */
|
---|
755 | #define LogFlowThisFuncLeave() LogFlowThisFunc(("LEAVE\n"))
|
---|
756 |
|
---|
757 | /** @def LogObjRefCnt
|
---|
758 | * Helper macro to print the current reference count of the given COM object
|
---|
759 | * to the log file.
|
---|
760 | *
|
---|
761 | * @param pObj Pointer to the object in question (must be a pointer to an
|
---|
762 | * IUnknown subclass or simply define COM-style AddRef() and
|
---|
763 | * Release() methods)
|
---|
764 | *
|
---|
765 | * @note Use it only for temporary debugging. It leaves dummy code even if
|
---|
766 | * logging is disabled.
|
---|
767 | */
|
---|
768 | #define LogObjRefCnt(pObj) \
|
---|
769 | do { \
|
---|
770 | int refc = (pObj)->AddRef(); \
|
---|
771 | LogFlow((#pObj "{%p}.refCnt=%d\n", (pObj), refc - 1)); \
|
---|
772 | (pObj)->Release(); \
|
---|
773 | } while (0)
|
---|
774 |
|
---|
775 |
|
---|
776 | /** @def LogIsItEnabled
|
---|
777 | * Checks whether the specified logging group is enabled or not.
|
---|
778 | */
|
---|
779 | #ifdef LOG_ENABLED
|
---|
780 | # define LogIsItEnabled(pvInst, fFlags, iGroup) \
|
---|
781 | LogIsItEnabledInternal((pvInst), (unsigned)(iGroup), (unsigned)(fFlags))
|
---|
782 | #else
|
---|
783 | # define LogIsItEnabled(pvInst, fFlags, iGroup) (false)
|
---|
784 | #endif
|
---|
785 |
|
---|
786 | /** @def LogIsEnabled
|
---|
787 | * Checks whether level 1 logging is enabled.
|
---|
788 | */
|
---|
789 | #define LogIsEnabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP)
|
---|
790 |
|
---|
791 | /** @def LogIs2Enabled
|
---|
792 | * Checks whether level 2 logging is enabled.
|
---|
793 | */
|
---|
794 | #define LogIs2Enabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP)
|
---|
795 |
|
---|
796 | /** @def LogIs3Enabled
|
---|
797 | * Checks whether level 3 logging is enabled.
|
---|
798 | */
|
---|
799 | #define LogIs3Enabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP)
|
---|
800 |
|
---|
801 | /** @def LogIs4Enabled
|
---|
802 | * Checks whether level 4 logging is enabled.
|
---|
803 | */
|
---|
804 | #define LogIs4Enabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP)
|
---|
805 |
|
---|
806 | /** @def LogIs5Enabled
|
---|
807 | * Checks whether level 5 logging is enabled.
|
---|
808 | */
|
---|
809 | #define LogIs5Enabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP)
|
---|
810 |
|
---|
811 | /** @def LogIs6Enabled
|
---|
812 | * Checks whether level 6 logging is enabled.
|
---|
813 | */
|
---|
814 | #define LogIs6Enabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP)
|
---|
815 |
|
---|
816 | /** @def LogIsFlowEnabled
|
---|
817 | * Checks whether execution flow logging is enabled.
|
---|
818 | */
|
---|
819 | #define LogIsFlowEnabled() LogIsItEnabled(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP)
|
---|
820 |
|
---|
821 |
|
---|
822 | /** @name Passing Function Call Position When Logging.
|
---|
823 | *
|
---|
824 | * This is a little bit ugly as we have to omit the comma before the
|
---|
825 | * position parameters so that we don't inccur any overhead in non-logging
|
---|
826 | * builds (!defined(LOG_ENABLED).
|
---|
827 | *
|
---|
828 | * @{ */
|
---|
829 | /** Source position for passing to a function call. */
|
---|
830 | #ifdef LOG_ENABLED
|
---|
831 | # define RTLOG_COMMA_SRC_POS , __FILE__, __LINE__, __PRETTY_FUNCTION__
|
---|
832 | #else
|
---|
833 | # define RTLOG_COMMA_SRC_POS RT_NOTHING
|
---|
834 | #endif
|
---|
835 | /** Source position declaration. */
|
---|
836 | #ifdef LOG_ENABLED
|
---|
837 | # define RTLOG_COMMA_SRC_POS_DECL , const char *pszFile, unsigned iLine, const char *pszFunction
|
---|
838 | #else
|
---|
839 | # define RTLOG_COMMA_SRC_POS_DECL RT_NOTHING
|
---|
840 | #endif
|
---|
841 | /** Source position arguments. */
|
---|
842 | #ifdef LOG_ENABLED
|
---|
843 | # define RTLOG_COMMA_SRC_POS_ARGS , pszFile, iLine, pszFunction
|
---|
844 | #else
|
---|
845 | # define RTLOG_COMMA_SRC_POS_ARGS RT_NOTHING
|
---|
846 | #endif
|
---|
847 | /** Applies NOREF() to the source position arguments. */
|
---|
848 | #ifdef LOG_ENABLED
|
---|
849 | # define RTLOG_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
|
---|
850 | #else
|
---|
851 | # define RTLOG_SRC_POS_NOREF() do { } while (0)
|
---|
852 | #endif
|
---|
853 | /** @} */
|
---|
854 |
|
---|
855 |
|
---|
856 |
|
---|
857 | /** @name Release Logging
|
---|
858 | * @{
|
---|
859 | */
|
---|
860 |
|
---|
861 | #ifdef DOXYGEN_RUNNING
|
---|
862 | # define RTLOG_REL_DISABLED
|
---|
863 | # define RTLOG_REL_ENABLED
|
---|
864 | #endif
|
---|
865 |
|
---|
866 | /** @def RTLOG_REL_DISABLED
|
---|
867 | * Use this compile time define to disable all release logging
|
---|
868 | * macros.
|
---|
869 | */
|
---|
870 |
|
---|
871 | /** @def RTLOG_REL_ENABLED
|
---|
872 | * Use this compile time define to override RTLOG_REL_DISABLE.
|
---|
873 | */
|
---|
874 |
|
---|
875 | /*
|
---|
876 | * Determin whether release logging is enabled and forcefully normalize the indicators.
|
---|
877 | */
|
---|
878 | #if !defined(RTLOG_REL_DISABLED) || defined(RTLOG_REL_ENABLED)
|
---|
879 | # undef RTLOG_REL_DISABLED
|
---|
880 | # undef RTLOG_REL_ENABLED
|
---|
881 | # define RTLOG_REL_ENABLED
|
---|
882 | #else
|
---|
883 | # undef RTLOG_REL_ENABLED
|
---|
884 | # undef RTLOG_REL_DISABLED
|
---|
885 | # define RTLOG_REL_DISABLED
|
---|
886 | #endif
|
---|
887 |
|
---|
888 |
|
---|
889 | /** @def LogIt
|
---|
890 | * Write to specific logger if group enabled.
|
---|
891 | */
|
---|
892 | #ifdef RTLOG_REL_ENABLED
|
---|
893 | # if defined(LOG_USE_C99)
|
---|
894 | # define _LogRelRemoveParentheseis(...) __VA_ARGS__
|
---|
895 | # define _LogRelIt(pvInst, fFlags, iGroup, ...) \
|
---|
896 | do \
|
---|
897 | { \
|
---|
898 | PRTLOGGER LogRelIt_pLogger = (PRTLOGGER)(pvInst) ? (PRTLOGGER)(pvInst) : RTLogRelDefaultInstance(); \
|
---|
899 | if (LogRelIt_pLogger) \
|
---|
900 | RTLogLoggerEx(LogRelIt_pLogger, fFlags, iGroup, __VA_ARGS__); \
|
---|
901 | _LogIt(LOG_INSTANCE, fFlags, iGroup, __VA_ARGS__); \
|
---|
902 | } while (0)
|
---|
903 | # define LogRelIt(pvInst, fFlags, iGroup, fmtargs) _LogRelIt(pvInst, fFlags, iGroup, _LogRelRemoveParentheseis fmtargs)
|
---|
904 | # else
|
---|
905 | # define LogRelIt(pvInst, fFlags, iGroup, fmtargs) \
|
---|
906 | do \
|
---|
907 | { \
|
---|
908 | PRTLOGGER LogRelIt_pLogger = (PRTLOGGER)(pvInst) ? (PRTLOGGER)(pvInst) : RTLogRelDefaultInstance(); \
|
---|
909 | if (LogRelIt_pLogger) \
|
---|
910 | { \
|
---|
911 | unsigned LogIt_fFlags = LogRelIt_pLogger->afGroups[(unsigned)(iGroup) < LogRelIt_pLogger->cGroups ? (unsigned)(iGroup) : 0]; \
|
---|
912 | if ((LogIt_fFlags & ((fFlags) | RTLOGGRPFLAGS_ENABLED)) == ((fFlags) | RTLOGGRPFLAGS_ENABLED)) \
|
---|
913 | LogRelIt_pLogger->pfnLogger fmtargs; \
|
---|
914 | } \
|
---|
915 | LogIt(LOG_INSTANCE, fFlags, iGroup, fmtargs); \
|
---|
916 | } while (0)
|
---|
917 | # endif
|
---|
918 | #else /* !RTLOG_REL_ENABLED */
|
---|
919 | # define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
|
---|
920 | # if defined(LOG_USE_C99)
|
---|
921 | # define _LogRelRemoveParentheseis(...) __VA_ARGS__
|
---|
922 | # define _LogRelIt(pvInst, fFlags, iGroup, ...) do { } while (0)
|
---|
923 | # endif
|
---|
924 | #endif /* !RTLOG_REL_ENABLED */
|
---|
925 |
|
---|
926 |
|
---|
927 | /** @def LogRel
|
---|
928 | * Level 1 logging.
|
---|
929 | */
|
---|
930 | #define LogRel(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
|
---|
931 |
|
---|
932 | /** @def LogRel2
|
---|
933 | * Level 2 logging.
|
---|
934 | */
|
---|
935 | #define LogRel2(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, a)
|
---|
936 |
|
---|
937 | /** @def LogRel3
|
---|
938 | * Level 3 logging.
|
---|
939 | */
|
---|
940 | #define LogRel3(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, a)
|
---|
941 |
|
---|
942 | /** @def LogRel4
|
---|
943 | * Level 4 logging.
|
---|
944 | */
|
---|
945 | #define LogRel4(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, a)
|
---|
946 |
|
---|
947 | /** @def LogRel5
|
---|
948 | * Level 5 logging.
|
---|
949 | */
|
---|
950 | #define LogRel5(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, a)
|
---|
951 |
|
---|
952 | /** @def LogRel6
|
---|
953 | * Level 6 logging.
|
---|
954 | */
|
---|
955 | #define LogRel6(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, a)
|
---|
956 |
|
---|
957 | /** @def LogRelFlow
|
---|
958 | * Logging of execution flow.
|
---|
959 | */
|
---|
960 | #define LogRelFlow(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, a)
|
---|
961 |
|
---|
962 | /** @def LogRelFunc
|
---|
963 | * Release logging. Prepends the given log message with the function name
|
---|
964 | * followed by a semicolon and space.
|
---|
965 | */
|
---|
966 | #ifdef LOG_USE_C99
|
---|
967 | # define LogRelFunc(a) \
|
---|
968 | _LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
969 | # define LogFunc(a) \
|
---|
970 | _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
971 | #else
|
---|
972 | # define LogRelFunc(a) \
|
---|
973 | do { LogRel((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRel(a); } while (0)
|
---|
974 | #endif
|
---|
975 |
|
---|
976 | /** @def LogRelThisFunc
|
---|
977 | * The same as LogRelFunc but for class functions (methods): the resulting log
|
---|
978 | * line is additionally prepended with a hex value of |this| pointer.
|
---|
979 | */
|
---|
980 | #ifdef LOG_USE_C99
|
---|
981 | # define LogRelThisFunc(a) \
|
---|
982 | _LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
983 | #else
|
---|
984 | # define LogRelThisFunc(a) \
|
---|
985 | do { LogRel(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogRel(a); } while (0)
|
---|
986 | #endif
|
---|
987 |
|
---|
988 | /** @def LogRelFlowFunc
|
---|
989 | * Release logging. Macro to log the execution flow inside C/C++ functions.
|
---|
990 | *
|
---|
991 | * Prepends the given log message with the function name followed by
|
---|
992 | * a semicolon and space.
|
---|
993 | *
|
---|
994 | * @param a Log message in format <tt>("string\n" [, args])</tt>.
|
---|
995 | */
|
---|
996 | #ifdef LOG_USE_C99
|
---|
997 | # define LogRelFlowFunc(a) \
|
---|
998 | _LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
|
---|
999 | #else
|
---|
1000 | # define LogRelFlowFunc(a) \
|
---|
1001 | do { LogRelFlow((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRelFlow(a); } while (0)
|
---|
1002 | #endif
|
---|
1003 |
|
---|
1004 | /** @def LogRelLelik
|
---|
1005 | * lelik logging.
|
---|
1006 | */
|
---|
1007 | #define LogRelLelik(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LELIK, LOG_GROUP, a)
|
---|
1008 |
|
---|
1009 | /** @def LogRelMichael
|
---|
1010 | * michael logging.
|
---|
1011 | */
|
---|
1012 | #define LogRelMichael(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_MICHAEL, LOG_GROUP, a)
|
---|
1013 |
|
---|
1014 | /** @def LogRelDmik
|
---|
1015 | * dmik logging.
|
---|
1016 | */
|
---|
1017 | #define LogRelDmik(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_DMIK, LOG_GROUP, a)
|
---|
1018 |
|
---|
1019 | /** @def LogRelSunlover
|
---|
1020 | * sunlover logging.
|
---|
1021 | */
|
---|
1022 | #define LogRelSunlover(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_SUNLOVER, LOG_GROUP, a)
|
---|
1023 |
|
---|
1024 | /** @def LogRelAchim
|
---|
1025 | * Achim logging.
|
---|
1026 | */
|
---|
1027 | #define LogRelAchim(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_ACHIM, LOG_GROUP, a)
|
---|
1028 |
|
---|
1029 | /** @def LogRelSander
|
---|
1030 | * Sander logging.
|
---|
1031 | */
|
---|
1032 | #define LogRelSander(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_SANDER, LOG_GROUP, a)
|
---|
1033 |
|
---|
1034 | /** @def LogRelKlaus
|
---|
1035 | * klaus logging.
|
---|
1036 | */
|
---|
1037 | #define LogRelKlaus(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_KLAUS, LOG_GROUP, a)
|
---|
1038 |
|
---|
1039 | /** @def LogRelFrank
|
---|
1040 | * frank logging.
|
---|
1041 | */
|
---|
1042 | #define LogRelFrank(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FRANK, LOG_GROUP, a)
|
---|
1043 |
|
---|
1044 | /** @def LogRelBird
|
---|
1045 | * bird logging.
|
---|
1046 | */
|
---|
1047 | #define LogRelBird(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_BIRD, LOG_GROUP, a)
|
---|
1048 |
|
---|
1049 | /** @def LogRelNoName
|
---|
1050 | * NoName logging.
|
---|
1051 | */
|
---|
1052 | #define LogRelNoName(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_NONAME, LOG_GROUP, a)
|
---|
1053 |
|
---|
1054 |
|
---|
1055 | /** @def LogRelIsItEnabled
|
---|
1056 | * Checks whether the specified logging group is enabled or not.
|
---|
1057 | */
|
---|
1058 | #define LogRelIsItEnabled(pvInst, fFlags, iGroup) \
|
---|
1059 | LogRelIsItEnabledInternal((pvInst), (unsigned)(iGroup), (unsigned)(fFlags))
|
---|
1060 |
|
---|
1061 | /** @def LogRelIsEnabled
|
---|
1062 | * Checks whether level 1 logging is enabled.
|
---|
1063 | */
|
---|
1064 | #define LogRelIsEnabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP)
|
---|
1065 |
|
---|
1066 | /** @def LogRelIs2Enabled
|
---|
1067 | * Checks whether level 2 logging is enabled.
|
---|
1068 | */
|
---|
1069 | #define LogRelIs2Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP)
|
---|
1070 |
|
---|
1071 | /** @def LogRelIs3Enabled
|
---|
1072 | * Checks whether level 3 logging is enabled.
|
---|
1073 | */
|
---|
1074 | #define LogRelIs3Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP)
|
---|
1075 |
|
---|
1076 | /** @def LogRelIs4Enabled
|
---|
1077 | * Checks whether level 4 logging is enabled.
|
---|
1078 | */
|
---|
1079 | #define LogRelIs4Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP)
|
---|
1080 |
|
---|
1081 | /** @def LogRelIs5Enabled
|
---|
1082 | * Checks whether level 5 logging is enabled.
|
---|
1083 | */
|
---|
1084 | #define LogRelIs5Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP)
|
---|
1085 |
|
---|
1086 | /** @def LogRelIs6Enabled
|
---|
1087 | * Checks whether level 6 logging is enabled.
|
---|
1088 | */
|
---|
1089 | #define LogRelIs6Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP)
|
---|
1090 |
|
---|
1091 | /** @def LogRelIsFlowEnabled
|
---|
1092 | * Checks whether execution flow logging is enabled.
|
---|
1093 | */
|
---|
1094 | #define LogRelIsFlowEnabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP)
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | #ifndef IN_RC
|
---|
1098 | /**
|
---|
1099 | * Sets the default release logger instance.
|
---|
1100 | *
|
---|
1101 | * @returns The old default instance.
|
---|
1102 | * @param pLogger The new default release logger instance.
|
---|
1103 | */
|
---|
1104 | RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger);
|
---|
1105 | #endif /* !IN_RC */
|
---|
1106 |
|
---|
1107 | /**
|
---|
1108 | * Gets the default release logger instance.
|
---|
1109 | *
|
---|
1110 | * @returns Pointer to default release logger instance.
|
---|
1111 | * @returns NULL if no default release logger instance available.
|
---|
1112 | */
|
---|
1113 | RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void);
|
---|
1114 |
|
---|
1115 | /** Internal worker function.
|
---|
1116 | * Don't call directly, use the LogRelIsItEnabled macro!
|
---|
1117 | */
|
---|
1118 | DECLINLINE(bool) LogRelIsItEnabledInternal(void *pvInst, unsigned iGroup, unsigned fFlags)
|
---|
1119 | {
|
---|
1120 | register PRTLOGGER pLogger = (PRTLOGGER)pvInst ? (PRTLOGGER)pvInst : RTLogRelDefaultInstance();
|
---|
1121 | if (pLogger)
|
---|
1122 | {
|
---|
1123 | register unsigned fGrpFlags = pLogger->afGroups[(unsigned)iGroup < pLogger->cGroups ? (unsigned)iGroup : 0];
|
---|
1124 | if ((fGrpFlags & (fFlags | RTLOGGRPFLAGS_ENABLED)) == (fFlags | RTLOGGRPFLAGS_ENABLED))
|
---|
1125 | return true;
|
---|
1126 | }
|
---|
1127 | return false;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | /**
|
---|
1131 | * Write to a logger instance, defaulting to the release one.
|
---|
1132 | *
|
---|
1133 | * This function will check whether the instance, group and flags makes up a
|
---|
1134 | * logging kind which is currently enabled before writing anything to the log.
|
---|
1135 | *
|
---|
1136 | * @param pLogger Pointer to logger instance.
|
---|
1137 | * @param fFlags The logging flags.
|
---|
1138 | * @param iGroup The group.
|
---|
1139 | * The value ~0U is reserved for compatability with RTLogLogger[V] and is
|
---|
1140 | * only for internal usage!
|
---|
1141 | * @param pszFormat Format string.
|
---|
1142 | * @param ... Format arguments.
|
---|
1143 | * @remark This is a worker function for LogRelIt.
|
---|
1144 | */
|
---|
1145 | RTDECL(void) RTLogRelLogger(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
|
---|
1146 |
|
---|
1147 | /**
|
---|
1148 | * Write to a logger instance, defaulting to the release one.
|
---|
1149 | *
|
---|
1150 | * This function will check whether the instance, group and flags makes up a
|
---|
1151 | * logging kind which is currently enabled before writing anything to the log.
|
---|
1152 | *
|
---|
1153 | * @param pLogger Pointer to logger instance. If NULL the default release instance is attempted.
|
---|
1154 | * @param fFlags The logging flags.
|
---|
1155 | * @param iGroup The group.
|
---|
1156 | * The value ~0U is reserved for compatability with RTLogLogger[V] and is
|
---|
1157 | * only for internal usage!
|
---|
1158 | * @param pszFormat Format string.
|
---|
1159 | * @param args Format arguments.
|
---|
1160 | */
|
---|
1161 | RTDECL(void) RTLogRelLoggerV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
|
---|
1162 |
|
---|
1163 | /**
|
---|
1164 | * printf like function for writing to the default release log.
|
---|
1165 | *
|
---|
1166 | * @param pszFormat Printf like format string.
|
---|
1167 | * @param ... Optional arguments as specified in pszFormat.
|
---|
1168 | *
|
---|
1169 | * @remark The API doesn't support formatting of floating point numbers at the moment.
|
---|
1170 | */
|
---|
1171 | RTDECL(void) RTLogRelPrintf(const char *pszFormat, ...);
|
---|
1172 |
|
---|
1173 | /**
|
---|
1174 | * vprintf like function for writing to the default release log.
|
---|
1175 | *
|
---|
1176 | * @param pszFormat Printf like format string.
|
---|
1177 | * @param args Optional arguments as specified in pszFormat.
|
---|
1178 | *
|
---|
1179 | * @remark The API doesn't support formatting of floating point numbers at the moment.
|
---|
1180 | */
|
---|
1181 | RTDECL(void) RTLogRelPrintfV(const char *pszFormat, va_list args);
|
---|
1182 |
|
---|
1183 | /**
|
---|
1184 | * Changes the buffering setting of the default release logger.
|
---|
1185 | *
|
---|
1186 | * This can be used for optimizing longish logging sequences.
|
---|
1187 | *
|
---|
1188 | * @returns The old state.
|
---|
1189 | * @param fBuffered The new state.
|
---|
1190 | */
|
---|
1191 | RTDECL(bool) RTLogRelSetBuffering(bool fBuffered);
|
---|
1192 |
|
---|
1193 | /** @} */
|
---|
1194 |
|
---|
1195 |
|
---|
1196 |
|
---|
1197 | /** @name COM port logging
|
---|
1198 | * {
|
---|
1199 | */
|
---|
1200 |
|
---|
1201 | #ifdef DOXYGEN_RUNNING
|
---|
1202 | # define LOG_TO_COM
|
---|
1203 | # define LOG_NO_COM
|
---|
1204 | #endif
|
---|
1205 |
|
---|
1206 | /** @def LOG_TO_COM
|
---|
1207 | * Redirects the normal loging macros to the serial versions.
|
---|
1208 | */
|
---|
1209 |
|
---|
1210 | /** @def LOG_NO_COM
|
---|
1211 | * Disables all LogCom* macros.
|
---|
1212 | */
|
---|
1213 |
|
---|
1214 | /** @def LogCom
|
---|
1215 | * Generic logging to serial port.
|
---|
1216 | */
|
---|
1217 | #if defined(LOG_ENABLED) && !defined(LOG_NO_COM)
|
---|
1218 | # define LogCom(a) RTLogComPrintf a
|
---|
1219 | #else
|
---|
1220 | # define LogCom(a) do { } while (0)
|
---|
1221 | #endif
|
---|
1222 |
|
---|
1223 | /** @def LogComFlow
|
---|
1224 | * Logging to serial port of execution flow.
|
---|
1225 | */
|
---|
1226 | #if defined(LOG_ENABLED) && defined(LOG_ENABLE_FLOW) && !defined(LOG_NO_COM)
|
---|
1227 | # define LogComFlow(a) RTLogComPrintf a
|
---|
1228 | #else
|
---|
1229 | # define LogComFlow(a) do { } while (0)
|
---|
1230 | #endif
|
---|
1231 |
|
---|
1232 | #ifdef LOG_TO_COM
|
---|
1233 | # undef Log
|
---|
1234 | # define Log(a) LogCom(a)
|
---|
1235 | # undef LogFlow
|
---|
1236 | # define LogFlow(a) LogComFlow(a)
|
---|
1237 | #endif
|
---|
1238 |
|
---|
1239 | /** @} */
|
---|
1240 |
|
---|
1241 |
|
---|
1242 | /** @name Backdoor Logging
|
---|
1243 | * @{
|
---|
1244 | */
|
---|
1245 |
|
---|
1246 | #ifdef DOXYGEN_RUNNING
|
---|
1247 | # define LOG_TO_BACKDOOR
|
---|
1248 | # define LOG_NO_BACKDOOR
|
---|
1249 | #endif
|
---|
1250 |
|
---|
1251 | /** @def LOG_TO_BACKDOOR
|
---|
1252 | * Redirects the normal logging macros to the backdoor versions.
|
---|
1253 | */
|
---|
1254 |
|
---|
1255 | /** @def LOG_NO_BACKDOOR
|
---|
1256 | * Disables all LogBackdoor* macros.
|
---|
1257 | */
|
---|
1258 |
|
---|
1259 | /** @def LogBackdoor
|
---|
1260 | * Generic logging to the VBox backdoor via port I/O.
|
---|
1261 | */
|
---|
1262 | #if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
|
---|
1263 | # define LogBackdoor(a) RTLogBackdoorPrintf a
|
---|
1264 | #else
|
---|
1265 | # define LogBackdoor(a) do { } while (0)
|
---|
1266 | #endif
|
---|
1267 |
|
---|
1268 | /** @def LogBackdoorFlow
|
---|
1269 | * Logging of execution flow messages to the backdoor I/O port.
|
---|
1270 | */
|
---|
1271 | #if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
|
---|
1272 | # define LogBackdoorFlow(a) RTLogBackdoorPrintf a
|
---|
1273 | #else
|
---|
1274 | # define LogBackdoorFlow(a) do { } while (0)
|
---|
1275 | #endif
|
---|
1276 |
|
---|
1277 | /** @def LogRelBackdoor
|
---|
1278 | * Release logging to the VBox backdoor via port I/O.
|
---|
1279 | */
|
---|
1280 | #if !defined(LOG_NO_BACKDOOR)
|
---|
1281 | # define LogRelBackdoor(a) RTLogBackdoorPrintf a
|
---|
1282 | #else
|
---|
1283 | # define LogRelBackdoor(a) do { } while (0)
|
---|
1284 | #endif
|
---|
1285 |
|
---|
1286 | #ifdef LOG_TO_BACKDOOR
|
---|
1287 | # undef Log
|
---|
1288 | # define Log(a) LogBackdoor(a)
|
---|
1289 | # undef LogFlow
|
---|
1290 | # define LogFlow(a) LogBackdoorFlow(a)
|
---|
1291 | # undef LogRel
|
---|
1292 | # define LogRel(a) LogRelBackdoor(a)
|
---|
1293 | # if defined(LOG_USE_C99)
|
---|
1294 | # undef _LogIt
|
---|
1295 | # define _LogIt(pvInst, fFlags, iGroup, ...) LogBackdoor((__VA_ARGS__))
|
---|
1296 | # endif
|
---|
1297 | #endif
|
---|
1298 |
|
---|
1299 | /** @} */
|
---|
1300 |
|
---|
1301 |
|
---|
1302 |
|
---|
1303 | /**
|
---|
1304 | * Gets the default logger instance, creating it if necessary.
|
---|
1305 | *
|
---|
1306 | * @returns Pointer to default logger instance.
|
---|
1307 | * @returns NULL if no default logger instance available.
|
---|
1308 | */
|
---|
1309 | RTDECL(PRTLOGGER) RTLogDefaultInstance(void);
|
---|
1310 |
|
---|
1311 | /**
|
---|
1312 | * Gets the default logger instance.
|
---|
1313 | *
|
---|
1314 | * @returns Pointer to default logger instance.
|
---|
1315 | * @returns NULL if no default logger instance available.
|
---|
1316 | */
|
---|
1317 | RTDECL(PRTLOGGER) RTLogGetDefaultInstance(void);
|
---|
1318 |
|
---|
1319 | #ifndef IN_RC
|
---|
1320 | /**
|
---|
1321 | * Sets the default logger instance.
|
---|
1322 | *
|
---|
1323 | * @returns The old default instance.
|
---|
1324 | * @param pLogger The new default logger instance.
|
---|
1325 | */
|
---|
1326 | RTDECL(PRTLOGGER) RTLogSetDefaultInstance(PRTLOGGER pLogger);
|
---|
1327 | #endif /* !IN_RC */
|
---|
1328 |
|
---|
1329 | #ifdef IN_RING0
|
---|
1330 | /**
|
---|
1331 | * Changes the default logger instance for the current thread.
|
---|
1332 | *
|
---|
1333 | * @returns IPRT status code.
|
---|
1334 | * @param pLogger The logger instance. Pass NULL for deregistration.
|
---|
1335 | * @param uKey Associated key for cleanup purposes. If pLogger is NULL,
|
---|
1336 | * all instances with this key will be deregistered. So in
|
---|
1337 | * order to only deregister the instance associated with the
|
---|
1338 | * current thread use 0.
|
---|
1339 | */
|
---|
1340 | RTDECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
|
---|
1341 | #endif /* IN_RING0 */
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | #ifdef LOG_ENABLED
|
---|
1345 | /** Internal worker function.
|
---|
1346 | * Don't call directly, use the LogIsItEnabled macro!
|
---|
1347 | */
|
---|
1348 | DECLINLINE(bool) LogIsItEnabledInternal(void *pvInst, unsigned iGroup, unsigned fFlags)
|
---|
1349 | {
|
---|
1350 | register PRTLOGGER pLogger = (PRTLOGGER)pvInst ? (PRTLOGGER)pvInst : RTLogDefaultInstance();
|
---|
1351 | if (pLogger)
|
---|
1352 | {
|
---|
1353 | register unsigned fGrpFlags = pLogger->afGroups[(unsigned)iGroup < pLogger->cGroups ? (unsigned)iGroup : 0];
|
---|
1354 | if ((fGrpFlags & (fFlags | RTLOGGRPFLAGS_ENABLED)) == (fFlags | RTLOGGRPFLAGS_ENABLED))
|
---|
1355 | return true;
|
---|
1356 | }
|
---|
1357 | return false;
|
---|
1358 | }
|
---|
1359 | #endif
|
---|
1360 |
|
---|
1361 |
|
---|
1362 | #ifndef IN_RC
|
---|
1363 | /**
|
---|
1364 | * Creates the default logger instance for a iprt users.
|
---|
1365 | *
|
---|
1366 | * Any user of the logging features will need to implement
|
---|
1367 | * this or use the generic dummy.
|
---|
1368 | *
|
---|
1369 | * @returns Pointer to the logger instance.
|
---|
1370 | */
|
---|
1371 | RTDECL(PRTLOGGER) RTLogDefaultInit(void);
|
---|
1372 |
|
---|
1373 | /**
|
---|
1374 | * Create a logger instance.
|
---|
1375 | *
|
---|
1376 | * @returns iprt status code.
|
---|
1377 | *
|
---|
1378 | * @param ppLogger Where to store the logger instance.
|
---|
1379 | * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
|
---|
1380 | * @param pszGroupSettings The initial group settings.
|
---|
1381 | * @param pszEnvVarBase Base name for the environment variables for this instance.
|
---|
1382 | * @param cGroups Number of groups in the array.
|
---|
1383 | * @param papszGroups Pointer to array of groups. This must stick around for the life of the
|
---|
1384 | * logger instance.
|
---|
1385 | * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
|
---|
1386 | * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
|
---|
1387 | * @param ... Format arguments.
|
---|
1388 | */
|
---|
1389 | RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
|
---|
1390 | const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
|
---|
1391 | uint32_t fDestFlags, const char *pszFilenameFmt, ...);
|
---|
1392 |
|
---|
1393 | /**
|
---|
1394 | * Create a logger instance.
|
---|
1395 | *
|
---|
1396 | * @returns iprt status code.
|
---|
1397 | *
|
---|
1398 | * @param ppLogger Where to store the logger instance.
|
---|
1399 | * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
|
---|
1400 | * @param pszGroupSettings The initial group settings.
|
---|
1401 | * @param pszEnvVarBase Base name for the environment variables for this instance.
|
---|
1402 | * @param cGroups Number of groups in the array.
|
---|
1403 | * @param papszGroups Pointer to array of groups. This must stick around for the life of the
|
---|
1404 | * logger instance.
|
---|
1405 | * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
|
---|
1406 | * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
|
---|
1407 | * @param cchErrorMsg The size of the error message buffer.
|
---|
1408 | * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
|
---|
1409 | * @param ... Format arguments.
|
---|
1410 | */
|
---|
1411 | RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
|
---|
1412 | const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
|
---|
1413 | uint32_t fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...);
|
---|
1414 |
|
---|
1415 | /**
|
---|
1416 | * Create a logger instance.
|
---|
1417 | *
|
---|
1418 | * @returns iprt status code.
|
---|
1419 | *
|
---|
1420 | * @param ppLogger Where to store the logger instance.
|
---|
1421 | * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
|
---|
1422 | * @param pszGroupSettings The initial group settings.
|
---|
1423 | * @param pszEnvVarBase Base name for the environment variables for this instance.
|
---|
1424 | * @param cGroups Number of groups in the array.
|
---|
1425 | * @param papszGroups Pointer to array of groups. This must stick around for the life of the
|
---|
1426 | * logger instance.
|
---|
1427 | * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
|
---|
1428 | * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
|
---|
1429 | * @param cchErrorMsg The size of the error message buffer.
|
---|
1430 | * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
|
---|
1431 | * @param args Format arguments.
|
---|
1432 | */
|
---|
1433 | RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
|
---|
1434 | const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
|
---|
1435 | uint32_t fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args);
|
---|
1436 |
|
---|
1437 | /**
|
---|
1438 | * Create a logger instance for singled threaded ring-0 usage.
|
---|
1439 | *
|
---|
1440 | * @returns iprt status code.
|
---|
1441 | *
|
---|
1442 | * @param pLogger Where to create the logger instance.
|
---|
1443 | * @param cbLogger The amount of memory available for the logger instance.
|
---|
1444 | * @param pfnLogger Pointer to logger wrapper function for the clone.
|
---|
1445 | * @param pfnFlush Pointer to flush function for the clone.
|
---|
1446 | * @param fFlags Logger instance flags for the clone, a combination of the RTLOGFLAGS_* values.
|
---|
1447 | * @param fDestFlags The destination flags.
|
---|
1448 | */
|
---|
1449 | RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger, PFNRTLOGGER pfnLogger, PFNRTLOGFLUSH pfnFlush, uint32_t fFlags, uint32_t fDestFlags);
|
---|
1450 |
|
---|
1451 | /**
|
---|
1452 | * Destroys a logger instance.
|
---|
1453 | *
|
---|
1454 | * The instance is flushed and all output destinations closed (where applicable).
|
---|
1455 | *
|
---|
1456 | * @returns iprt status code.
|
---|
1457 | * @param pLogger The logger instance which close destroyed. NULL is fine.
|
---|
1458 | */
|
---|
1459 | RTDECL(int) RTLogDestroy(PRTLOGGER pLogger);
|
---|
1460 |
|
---|
1461 | /**
|
---|
1462 | * Create a logger instance clone for RC usage.
|
---|
1463 | *
|
---|
1464 | * @returns iprt status code.
|
---|
1465 | *
|
---|
1466 | * @param pLogger The logger instance to be cloned.
|
---|
1467 | * @param pLoggerRC Where to create the RC logger instance.
|
---|
1468 | * @param cbLoggerRC Amount of memory allocated to for the RC logger
|
---|
1469 | * instance clone.
|
---|
1470 | * @param pfnLoggerRCPtr Pointer to logger wrapper function for this
|
---|
1471 | * instance (RC Ptr).
|
---|
1472 | * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).
|
---|
1473 | * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
|
---|
1474 | */
|
---|
1475 | RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,
|
---|
1476 | RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, uint32_t fFlags);
|
---|
1477 |
|
---|
1478 | /**
|
---|
1479 | * Flushes a RC logger instance to a R3 logger.
|
---|
1480 | *
|
---|
1481 | * @returns iprt status code.
|
---|
1482 | * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL
|
---|
1483 | * the default logger is used.
|
---|
1484 | * @param pLoggerRC The RC logger instance to flush.
|
---|
1485 | */
|
---|
1486 | RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC);
|
---|
1487 |
|
---|
1488 | /**
|
---|
1489 | * Flushes the buffer in one logger instance onto another logger.
|
---|
1490 | *
|
---|
1491 | * @returns iprt status code.
|
---|
1492 | *
|
---|
1493 | * @param pSrcLogger The logger instance to flush.
|
---|
1494 | * @param pDstLogger The logger instance to flush onto.
|
---|
1495 | * If NULL the default logger will be used.
|
---|
1496 | */
|
---|
1497 | RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger);
|
---|
1498 |
|
---|
1499 | /**
|
---|
1500 | * Sets the custom prefix callback.
|
---|
1501 | *
|
---|
1502 | * @returns IPRT status code.
|
---|
1503 | * @param pLogger The logger instance.
|
---|
1504 | * @param pfnCallback The callback.
|
---|
1505 | * @param pvUser The user argument for the callback.
|
---|
1506 | * */
|
---|
1507 | RTDECL(int) RTLogSetCustomPrefixCallback(PRTLOGGER pLogger, PFNRTLOGPREFIX pfnCallback, void *pvUser);
|
---|
1508 |
|
---|
1509 | /**
|
---|
1510 | * Copies the group settings and flags from logger instance to another.
|
---|
1511 | *
|
---|
1512 | * @returns IPRT status code.
|
---|
1513 | * @param pDstLogger The destination logger instance.
|
---|
1514 | * @param pSrcLogger The source logger instance. If NULL the default one is used.
|
---|
1515 | * @param fFlagsOr OR mask for the flags.
|
---|
1516 | * @param fFlagsAnd AND mask for the flags.
|
---|
1517 | */
|
---|
1518 | RTDECL(int) RTLogCopyGroupsAndFlags(PRTLOGGER pDstLogger, PCRTLOGGER pSrcLogger, unsigned fFlagsOr, unsigned fFlagsAnd);
|
---|
1519 |
|
---|
1520 | /**
|
---|
1521 | * Get the current log group settings as a string.
|
---|
1522 | *
|
---|
1523 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
|
---|
1524 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1525 | * @param pszBuf The output buffer.
|
---|
1526 | * @param cchBuf The size of the output buffer. Must be greater
|
---|
1527 | * than zero.
|
---|
1528 | */
|
---|
1529 | RTDECL(int) RTLogGetGroupSettings(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
|
---|
1530 |
|
---|
1531 | /**
|
---|
1532 | * Updates the group settings for the logger instance using the specified
|
---|
1533 | * specification string.
|
---|
1534 | *
|
---|
1535 | * @returns iprt status code.
|
---|
1536 | * Failures can safely be ignored.
|
---|
1537 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1538 | * @param pszVar Value to parse.
|
---|
1539 | */
|
---|
1540 | RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszVar);
|
---|
1541 | #endif /* !IN_RC */
|
---|
1542 |
|
---|
1543 | /**
|
---|
1544 | * Updates the flags for the logger instance using the specified
|
---|
1545 | * specification string.
|
---|
1546 | *
|
---|
1547 | * @returns iprt status code.
|
---|
1548 | * Failures can safely be ignored.
|
---|
1549 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1550 | * @param pszVar Value to parse.
|
---|
1551 | */
|
---|
1552 | RTDECL(int) RTLogFlags(PRTLOGGER pLogger, const char *pszVar);
|
---|
1553 |
|
---|
1554 | /**
|
---|
1555 | * Changes the buffering setting of the specified logger.
|
---|
1556 | *
|
---|
1557 | * This can be used for optimizing longish logging sequences.
|
---|
1558 | *
|
---|
1559 | * @returns The old state.
|
---|
1560 | * @param pLogger The logger instance (NULL is an alias for the
|
---|
1561 | * default logger).
|
---|
1562 | * @param fBuffered The new state.
|
---|
1563 | */
|
---|
1564 | RTDECL(bool) RTLogSetBuffering(PRTLOGGER pLogger, bool fBuffered);
|
---|
1565 |
|
---|
1566 | #ifndef IN_RC
|
---|
1567 | /**
|
---|
1568 | * Get the current log flags as a string.
|
---|
1569 | *
|
---|
1570 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
|
---|
1571 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1572 | * @param pszBuf The output buffer.
|
---|
1573 | * @param cchBuf The size of the output buffer. Must be greater
|
---|
1574 | * than zero.
|
---|
1575 | */
|
---|
1576 | RTDECL(int) RTLogGetFlags(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
|
---|
1577 |
|
---|
1578 | /**
|
---|
1579 | * Updates the logger desination using the specified string.
|
---|
1580 | *
|
---|
1581 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
|
---|
1582 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1583 | * @param pszVar The value to parse.
|
---|
1584 | */
|
---|
1585 | RTDECL(int) RTLogDestinations(PRTLOGGER pLogger, char const *pszVar);
|
---|
1586 |
|
---|
1587 | /**
|
---|
1588 | * Get the current log destinations as a string.
|
---|
1589 | *
|
---|
1590 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
|
---|
1591 | * @param pLogger Logger instance (NULL for default logger).
|
---|
1592 | * @param pszBuf The output buffer.
|
---|
1593 | * @param cchBuf The size of the output buffer. Must be greater
|
---|
1594 | * than 0.
|
---|
1595 | */
|
---|
1596 | RTDECL(int) RTLogGetDestinations(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
|
---|
1597 | #endif /* !IN_RC */
|
---|
1598 |
|
---|
1599 | /**
|
---|
1600 | * Flushes the specified logger.
|
---|
1601 | *
|
---|
1602 | * @param pLogger The logger instance to flush.
|
---|
1603 | * If NULL the default instance is used. The default instance
|
---|
1604 | * will not be initialized by this call.
|
---|
1605 | */
|
---|
1606 | RTDECL(void) RTLogFlush(PRTLOGGER pLogger);
|
---|
1607 |
|
---|
1608 | /**
|
---|
1609 | * Write to a logger instance.
|
---|
1610 | *
|
---|
1611 | * @param pLogger Pointer to logger instance.
|
---|
1612 | * @param pvCallerRet Ignored.
|
---|
1613 | * @param pszFormat Format string.
|
---|
1614 | * @param ... Format arguments.
|
---|
1615 | */
|
---|
1616 | RTDECL(void) RTLogLogger(PRTLOGGER pLogger, void *pvCallerRet, const char *pszFormat, ...);
|
---|
1617 |
|
---|
1618 | /**
|
---|
1619 | * Write to a logger instance.
|
---|
1620 | *
|
---|
1621 | * @param pLogger Pointer to logger instance.
|
---|
1622 | * @param pszFormat Format string.
|
---|
1623 | * @param args Format arguments.
|
---|
1624 | */
|
---|
1625 | RTDECL(void) RTLogLoggerV(PRTLOGGER pLogger, const char *pszFormat, va_list args);
|
---|
1626 |
|
---|
1627 | /**
|
---|
1628 | * Write to a logger instance.
|
---|
1629 | *
|
---|
1630 | * This function will check whether the instance, group and flags makes up a
|
---|
1631 | * logging kind which is currently enabled before writing anything to the log.
|
---|
1632 | *
|
---|
1633 | * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
|
---|
1634 | * @param fFlags The logging flags.
|
---|
1635 | * @param iGroup The group.
|
---|
1636 | * The value ~0U is reserved for compatability with RTLogLogger[V] and is
|
---|
1637 | * only for internal usage!
|
---|
1638 | * @param pszFormat Format string.
|
---|
1639 | * @param ... Format arguments.
|
---|
1640 | * @remark This is a worker function of LogIt.
|
---|
1641 | */
|
---|
1642 | RTDECL(void) RTLogLoggerEx(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
|
---|
1643 |
|
---|
1644 | /**
|
---|
1645 | * Write to a logger instance.
|
---|
1646 | *
|
---|
1647 | * This function will check whether the instance, group and flags makes up a
|
---|
1648 | * logging kind which is currently enabled before writing anything to the log.
|
---|
1649 | *
|
---|
1650 | * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
|
---|
1651 | * @param fFlags The logging flags.
|
---|
1652 | * @param iGroup The group.
|
---|
1653 | * The value ~0U is reserved for compatability with RTLogLogger[V] and is
|
---|
1654 | * only for internal usage!
|
---|
1655 | * @param pszFormat Format string.
|
---|
1656 | * @param args Format arguments.
|
---|
1657 | */
|
---|
1658 | RTDECL(void) RTLogLoggerExV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
|
---|
1659 |
|
---|
1660 | /**
|
---|
1661 | * printf like function for writing to the default log.
|
---|
1662 | *
|
---|
1663 | * @param pszFormat Printf like format string.
|
---|
1664 | * @param ... Optional arguments as specified in pszFormat.
|
---|
1665 | *
|
---|
1666 | * @remark The API doesn't support formatting of floating point numbers at the moment.
|
---|
1667 | */
|
---|
1668 | RTDECL(void) RTLogPrintf(const char *pszFormat, ...);
|
---|
1669 |
|
---|
1670 | /**
|
---|
1671 | * vprintf like function for writing to the default log.
|
---|
1672 | *
|
---|
1673 | * @param pszFormat Printf like format string.
|
---|
1674 | * @param args Optional arguments as specified in pszFormat.
|
---|
1675 | *
|
---|
1676 | * @remark The API doesn't support formatting of floating point numbers at the moment.
|
---|
1677 | */
|
---|
1678 | RTDECL(void) RTLogPrintfV(const char *pszFormat, va_list args);
|
---|
1679 |
|
---|
1680 |
|
---|
1681 | #ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/string.h */
|
---|
1682 | #define DECLARED_FNRTSTROUTPUT
|
---|
1683 | /**
|
---|
1684 | * Output callback.
|
---|
1685 | *
|
---|
1686 | * @returns number of bytes written.
|
---|
1687 | * @param pvArg User argument.
|
---|
1688 | * @param pachChars Pointer to an array of utf-8 characters.
|
---|
1689 | * @param cbChars Number of bytes in the character array pointed to by pachChars.
|
---|
1690 | */
|
---|
1691 | typedef DECLCALLBACK(size_t) FNRTSTROUTPUT(void *pvArg, const char *pachChars, size_t cbChars);
|
---|
1692 | /** Pointer to callback function. */
|
---|
1693 | typedef FNRTSTROUTPUT *PFNRTSTROUTPUT;
|
---|
1694 | #endif
|
---|
1695 |
|
---|
1696 | /**
|
---|
1697 | * Partial vsprintf worker implementation.
|
---|
1698 | *
|
---|
1699 | * @returns number of bytes formatted.
|
---|
1700 | * @param pfnOutput Output worker.
|
---|
1701 | * Called in two ways. Normally with a string an it's length.
|
---|
1702 | * For termination, it's called with NULL for string, 0 for length.
|
---|
1703 | * @param pvArg Argument to output worker.
|
---|
1704 | * @param pszFormat Format string.
|
---|
1705 | * @param args Argument list.
|
---|
1706 | */
|
---|
1707 | RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args);
|
---|
1708 |
|
---|
1709 | /**
|
---|
1710 | * Write log buffer to COM port.
|
---|
1711 | *
|
---|
1712 | * @param pach Pointer to the buffer to write.
|
---|
1713 | * @param cb Number of bytes to write.
|
---|
1714 | */
|
---|
1715 | RTDECL(void) RTLogWriteCom(const char *pach, size_t cb);
|
---|
1716 |
|
---|
1717 | /**
|
---|
1718 | * Prints a formatted string to the serial port used for logging.
|
---|
1719 | *
|
---|
1720 | * @returns Number of bytes written.
|
---|
1721 | * @param pszFormat Format string.
|
---|
1722 | * @param ... Optional arguments specified in the format string.
|
---|
1723 | */
|
---|
1724 | RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...);
|
---|
1725 |
|
---|
1726 | /**
|
---|
1727 | * Prints a formatted string to the serial port used for logging.
|
---|
1728 | *
|
---|
1729 | * @returns Number of bytes written.
|
---|
1730 | * @param pszFormat Format string.
|
---|
1731 | * @param args Optional arguments specified in the format string.
|
---|
1732 | */
|
---|
1733 | RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args);
|
---|
1734 |
|
---|
1735 |
|
---|
1736 | #if 0 /* not implemented yet */
|
---|
1737 |
|
---|
1738 | /** Indicates that the semaphores shall be used to notify the other
|
---|
1739 | * part about buffer changes. */
|
---|
1740 | #define LOGHOOKBUFFER_FLAGS_SEMAPHORED 1
|
---|
1741 |
|
---|
1742 | /**
|
---|
1743 | * Log Hook Buffer.
|
---|
1744 | * Use to commuicate between the logger and a log consumer.
|
---|
1745 | */
|
---|
1746 | typedef struct RTLOGHOOKBUFFER
|
---|
1747 | {
|
---|
1748 | /** Write pointer. */
|
---|
1749 | volatile void *pvWrite;
|
---|
1750 | /** Read pointer. */
|
---|
1751 | volatile void *pvRead;
|
---|
1752 | /** Buffer start. */
|
---|
1753 | void *pvStart;
|
---|
1754 | /** Buffer end (exclusive). */
|
---|
1755 | void *pvEnd;
|
---|
1756 | /** Signaling semaphore used by the writer to wait on a full buffer.
|
---|
1757 | * Only used when indicated in flags. */
|
---|
1758 | void *pvSemWriter;
|
---|
1759 | /** Signaling semaphore used by the read to wait on an empty buffer.
|
---|
1760 | * Only used when indicated in flags. */
|
---|
1761 | void *pvSemReader;
|
---|
1762 | /** Buffer flags. Current reserved and set to zero. */
|
---|
1763 | volatile unsigned fFlags;
|
---|
1764 | } RTLOGHOOKBUFFER;
|
---|
1765 | /** Pointer to a log hook buffer. */
|
---|
1766 | typedef RTLOGHOOKBUFFER *PRTLOGHOOKBUFFER;
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | /**
|
---|
1770 | * Register a logging hook.
|
---|
1771 | *
|
---|
1772 | * This type of logging hooks are expecting different threads acting
|
---|
1773 | * producer and consumer. They share a circular buffer which have two
|
---|
1774 | * pointers one for each end. When the buffer is full there are two
|
---|
1775 | * alternatives (indicated by a buffer flag), either wait for the
|
---|
1776 | * consumer to get it's job done, or to write a generic message saying
|
---|
1777 | * buffer overflow.
|
---|
1778 | *
|
---|
1779 | * Since the waiting would need a signal semaphore, we'll skip that for now.
|
---|
1780 | *
|
---|
1781 | * @returns iprt status code.
|
---|
1782 | * @param pBuffer Pointer to a logger hook buffer.
|
---|
1783 | */
|
---|
1784 | RTDECL(int) RTLogRegisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
|
---|
1785 |
|
---|
1786 | /**
|
---|
1787 | * Deregister a logging hook registerd with RTLogRegisterHook().
|
---|
1788 | *
|
---|
1789 | * @returns iprt status code.
|
---|
1790 | * @param pBuffer Pointer to a logger hook buffer.
|
---|
1791 | */
|
---|
1792 | RTDECL(int) RTLogDeregisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
|
---|
1793 |
|
---|
1794 | #endif /* not implemented yet */
|
---|
1795 |
|
---|
1796 |
|
---|
1797 |
|
---|
1798 | /**
|
---|
1799 | * Write log buffer to a debugger (RTLOGDEST_DEBUGGER).
|
---|
1800 | *
|
---|
1801 | * @param pach What to write.
|
---|
1802 | * @param cb How much to write.
|
---|
1803 | * @remark When linking statically, this function can be replaced by defining your own.
|
---|
1804 | */
|
---|
1805 | RTDECL(void) RTLogWriteDebugger(const char *pach, size_t cb);
|
---|
1806 |
|
---|
1807 | /**
|
---|
1808 | * Write log buffer to a user defined output stream (RTLOGDEST_USER).
|
---|
1809 | *
|
---|
1810 | * @param pach What to write.
|
---|
1811 | * @param cb How much to write.
|
---|
1812 | * @remark When linking statically, this function can be replaced by defining your own.
|
---|
1813 | */
|
---|
1814 | RTDECL(void) RTLogWriteUser(const char *pach, size_t cb);
|
---|
1815 |
|
---|
1816 | /**
|
---|
1817 | * Write log buffer to stdout (RTLOGDEST_STDOUT).
|
---|
1818 | *
|
---|
1819 | * @param pach What to write.
|
---|
1820 | * @param cb How much to write.
|
---|
1821 | * @remark When linking statically, this function can be replaced by defining your own.
|
---|
1822 | */
|
---|
1823 | RTDECL(void) RTLogWriteStdOut(const char *pach, size_t cb);
|
---|
1824 |
|
---|
1825 | /**
|
---|
1826 | * Write log buffer to stdout (RTLOGDEST_STDERR).
|
---|
1827 | *
|
---|
1828 | * @param pach What to write.
|
---|
1829 | * @param cb How much to write.
|
---|
1830 | * @remark When linking statically, this function can be replaced by defining your own.
|
---|
1831 | */
|
---|
1832 | RTDECL(void) RTLogWriteStdErr(const char *pach, size_t cb);
|
---|
1833 |
|
---|
1834 | #ifdef VBOX
|
---|
1835 |
|
---|
1836 | /**
|
---|
1837 | * Prints a formatted string to the backdoor port.
|
---|
1838 | *
|
---|
1839 | * @returns Number of bytes written.
|
---|
1840 | * @param pszFormat Format string.
|
---|
1841 | * @param ... Optional arguments specified in the format string.
|
---|
1842 | */
|
---|
1843 | RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...);
|
---|
1844 |
|
---|
1845 | /**
|
---|
1846 | * Prints a formatted string to the backdoor port.
|
---|
1847 | *
|
---|
1848 | * @returns Number of bytes written.
|
---|
1849 | * @param pszFormat Format string.
|
---|
1850 | * @param args Optional arguments specified in the format string.
|
---|
1851 | */
|
---|
1852 | RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args);
|
---|
1853 |
|
---|
1854 | #endif /* VBOX */
|
---|
1855 |
|
---|
1856 | RT_C_DECLS_END
|
---|
1857 |
|
---|
1858 | /** @} */
|
---|
1859 |
|
---|
1860 | #endif
|
---|
1861 |
|
---|