VirtualBox

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

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

Ring-0 assertions are now always printed to the debug log.
Introduced LogAlways for this purpose.

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