VirtualBox

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

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

LogRelBackdoor and map LogRel to it when LOG_TO_BACKDOOR is defined.

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