VirtualBox

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

Last change on this file since 17215 was 13832, checked in by vboxsync, 16 years ago

IN_GC -> IN_RC.

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