VirtualBox

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

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

Added a cpuid / apicid logging prefix. New *_LOG_FLAGS is 'cpuid'.

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