VirtualBox

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

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

Runtime: Added RTLogSetDefaultInstance().

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