VirtualBox

source: vbox/trunk/include/iprt/log.h@ 8746

Last change on this file since 8746 was 8663, checked in by vboxsync, 17 years ago

New logger prefix: lockcnts Output: read/write

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette