VirtualBox

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

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

Runtime/Logger: added "LOG_TO_BACKDOOR_FULL" for guest R3 executables to control what is (debug) logged to the backdoor logger using the usual VBOX_LOG environment variable

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