VirtualBox

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

Last change on this file since 12131 was 12131, checked in by vboxsync, 16 years ago

Comment added

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