VirtualBox

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

Last change on this file since 18645 was 18188, checked in by vboxsync, 16 years ago

Added RTLogGetDefaultInstance

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.2 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, creating it if necessary.
1206 *
1207 * @returns Pointer to default logger instance.
1208 * @returns NULL if no default logger instance available.
1209 */
1210RTDECL(PRTLOGGER) RTLogDefaultInstance(void);
1211
1212/**
1213 * Gets the default logger instance.
1214 *
1215 * @returns Pointer to default logger instance.
1216 * @returns NULL if no default logger instance available.
1217 */
1218RTDECL(PRTLOGGER) RTLogGetDefaultInstance(void);
1219
1220#ifndef IN_RC
1221/**
1222 * Sets the default logger instance.
1223 *
1224 * @returns The old default instance.
1225 * @param pLogger The new default logger instance.
1226 */
1227RTDECL(PRTLOGGER) RTLogSetDefaultInstance(PRTLOGGER pLogger);
1228#endif /* !IN_RC */
1229
1230#ifdef IN_RING0
1231/**
1232 * Changes the default logger instance for the current thread.
1233 *
1234 * @returns IPRT status code.
1235 * @param pLogger The logger instance. Pass NULL for deregistration.
1236 * @param uKey Associated key for cleanup purposes. If pLogger is NULL,
1237 * all instances with this key will be deregistered. So in
1238 * order to only deregister the instance associated with the
1239 * current thread use 0.
1240 */
1241RTDECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
1242#endif /* IN_RING0 */
1243
1244
1245#ifdef LOG_ENABLED
1246/** Internal worker function.
1247 * Don't call directly, use the LogIsItEnabled macro!
1248 */
1249DECLINLINE(bool) LogIsItEnabledInternal(void *pvInst, unsigned iGroup, unsigned fFlags)
1250{
1251 register PRTLOGGER pLogger = (PRTLOGGER)pvInst ? (PRTLOGGER)pvInst : RTLogDefaultInstance();
1252 if (pLogger)
1253 {
1254 register unsigned fGrpFlags = pLogger->afGroups[(unsigned)iGroup < pLogger->cGroups ? (unsigned)iGroup : 0];
1255 if ((fGrpFlags & (fFlags | RTLOGGRPFLAGS_ENABLED)) == (fFlags | RTLOGGRPFLAGS_ENABLED))
1256 return true;
1257 }
1258 return false;
1259}
1260#endif
1261
1262
1263#ifndef IN_RC
1264/**
1265 * Creates the default logger instance for a iprt users.
1266 *
1267 * Any user of the logging features will need to implement
1268 * this or use the generic dummy.
1269 *
1270 * @returns Pointer to the logger instance.
1271 */
1272RTDECL(PRTLOGGER) RTLogDefaultInit(void);
1273
1274/**
1275 * Create a logger instance.
1276 *
1277 * @returns iprt status code.
1278 *
1279 * @param ppLogger Where to store the logger instance.
1280 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1281 * @param pszGroupSettings The initial group settings.
1282 * @param pszEnvVarBase Base name for the environment variables for this instance.
1283 * @param cGroups Number of groups in the array.
1284 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1285 * logger instance.
1286 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1287 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1288 * @param ... Format arguments.
1289 */
1290RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1291 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1292 RTUINT fDestFlags, const char *pszFilenameFmt, ...);
1293
1294/**
1295 * Create a logger instance.
1296 *
1297 * @returns iprt status code.
1298 *
1299 * @param ppLogger Where to store the logger instance.
1300 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1301 * @param pszGroupSettings The initial group settings.
1302 * @param pszEnvVarBase Base name for the environment variables for this instance.
1303 * @param cGroups Number of groups in the array.
1304 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1305 * logger instance.
1306 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1307 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
1308 * @param cchErrorMsg The size of the error message buffer.
1309 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1310 * @param ... Format arguments.
1311 */
1312RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1313 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1314 RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...);
1315
1316/**
1317 * Create a logger instance.
1318 *
1319 * @returns iprt status code.
1320 *
1321 * @param ppLogger Where to store the logger instance.
1322 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1323 * @param pszGroupSettings The initial group settings.
1324 * @param pszEnvVarBase Base name for the environment variables for this instance.
1325 * @param cGroups Number of groups in the array.
1326 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1327 * logger instance.
1328 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1329 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
1330 * @param cchErrorMsg The size of the error message buffer.
1331 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1332 * @param args Format arguments.
1333 */
1334RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1335 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1336 RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args);
1337
1338/**
1339 * Create a logger instance for singled threaded ring-0 usage.
1340 *
1341 * @returns iprt status code.
1342 *
1343 * @param pLogger Where to create the logger instance.
1344 * @param cbLogger The amount of memory available for the logger instance.
1345 * @param pfnLogger Pointer to logger wrapper function for the clone.
1346 * @param pfnFlush Pointer to flush function for the clone.
1347 * @param fFlags Logger instance flags for the clone, a combination of the RTLOGFLAGS_* values.
1348 * @param fDestFlags The destination flags.
1349 */
1350RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger, PFNRTLOGGER pfnLogger, PFNRTLOGFLUSH pfnFlush, RTUINT fFlags, RTUINT fDestFlags);
1351
1352/**
1353 * Destroys a logger instance.
1354 *
1355 * The instance is flushed and all output destinations closed (where applicable).
1356 *
1357 * @returns iprt status code.
1358 * @param pLogger The logger instance which close destroyed. NULL is fine.
1359 */
1360RTDECL(int) RTLogDestroy(PRTLOGGER pLogger);
1361
1362/**
1363 * Create a logger instance clone for RC usage.
1364 *
1365 * @returns iprt status code.
1366 *
1367 * @param pLogger The logger instance to be cloned.
1368 * @param pLoggerRC Where to create the RC logger instance.
1369 * @param cbLoggerRC Amount of memory allocated to for the RC logger
1370 * instance clone.
1371 * @param pfnLoggerRCPtr Pointer to logger wrapper function for this
1372 * instance (RC Ptr).
1373 * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).
1374 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1375 */
1376RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,
1377 RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, RTUINT fFlags);
1378
1379/**
1380 * Flushes a RC logger instance to a R3 logger.
1381 *
1382 * @returns iprt status code.
1383 * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL
1384 * the default logger is used.
1385 * @param pLoggerRC The RC logger instance to flush.
1386 */
1387RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC);
1388
1389/**
1390 * Flushes the buffer in one logger instance onto another logger.
1391 *
1392 * @returns iprt status code.
1393 *
1394 * @param pSrcLogger The logger instance to flush.
1395 * @param pDstLogger The logger instance to flush onto.
1396 * If NULL the default logger will be used.
1397 */
1398RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger);
1399
1400/**
1401 * Copies the group settings and flags from logger instance to another.
1402 *
1403 * @returns IPRT status code.
1404 * @param pDstLogger The destination logger instance.
1405 * @param pSrcLogger The source logger instance. If NULL the default one is used.
1406 * @param fFlagsOr OR mask for the flags.
1407 * @param fFlagsAnd AND mask for the flags.
1408 */
1409RTDECL(int) RTLogCopyGroupsAndFlags(PRTLOGGER pDstLogger, PCRTLOGGER pSrcLogger, unsigned fFlagsOr, unsigned fFlagsAnd);
1410
1411/**
1412 * Updates the group settings for the logger instance using the specified
1413 * specification string.
1414 *
1415 * @returns iprt status code.
1416 * Failures can safely be ignored.
1417 * @param pLogger Logger instance (NULL for default logger).
1418 * @param pszVar Value to parse.
1419 */
1420RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszVar);
1421#endif /* !IN_RC */
1422
1423/**
1424 * Updates the flags for the logger instance using the specified
1425 * specification string.
1426 *
1427 * @returns iprt status code.
1428 * Failures can safely be ignored.
1429 * @param pLogger Logger instance (NULL for default logger).
1430 * @param pszVar Value to parse.
1431 */
1432RTDECL(int) RTLogFlags(PRTLOGGER pLogger, const char *pszVar);
1433
1434/**
1435 * Flushes the specified logger.
1436 *
1437 * @param pLogger The logger instance to flush.
1438 * If NULL the default instance is used. The default instance
1439 * will not be initialized by this call.
1440 */
1441RTDECL(void) RTLogFlush(PRTLOGGER pLogger);
1442
1443/**
1444 * Write to a logger instance.
1445 *
1446 * @param pLogger Pointer to logger instance.
1447 * @param pvCallerRet Ignored.
1448 * @param pszFormat Format string.
1449 * @param ... Format arguments.
1450 */
1451RTDECL(void) RTLogLogger(PRTLOGGER pLogger, void *pvCallerRet, const char *pszFormat, ...);
1452
1453/**
1454 * Write to a logger instance.
1455 *
1456 * @param pLogger Pointer to logger instance.
1457 * @param pszFormat Format string.
1458 * @param args Format arguments.
1459 */
1460RTDECL(void) RTLogLoggerV(PRTLOGGER pLogger, const char *pszFormat, va_list args);
1461
1462/**
1463 * Write to a logger instance.
1464 *
1465 * This function will check whether the instance, group and flags makes up a
1466 * logging kind which is currently enabled before writing anything to the log.
1467 *
1468 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
1469 * @param fFlags The logging flags.
1470 * @param iGroup The group.
1471 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1472 * only for internal usage!
1473 * @param pszFormat Format string.
1474 * @param ... Format arguments.
1475 * @remark This is a worker function of LogIt.
1476 */
1477RTDECL(void) RTLogLoggerEx(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
1478
1479/**
1480 * Write to a logger instance.
1481 *
1482 * This function will check whether the instance, group and flags makes up a
1483 * logging kind which is currently enabled before writing anything to the log.
1484 *
1485 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
1486 * @param fFlags The logging flags.
1487 * @param iGroup The group.
1488 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1489 * only for internal usage!
1490 * @param pszFormat Format string.
1491 * @param args Format arguments.
1492 */
1493RTDECL(void) RTLogLoggerExV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
1494
1495/**
1496 * printf like function for writing to the default log.
1497 *
1498 * @param pszFormat Printf like format string.
1499 * @param ... Optional arguments as specified in pszFormat.
1500 *
1501 * @remark The API doesn't support formatting of floating point numbers at the moment.
1502 */
1503RTDECL(void) RTLogPrintf(const char *pszFormat, ...);
1504
1505/**
1506 * vprintf like function for writing to the default log.
1507 *
1508 * @param pszFormat Printf like format string.
1509 * @param args Optional arguments as specified in pszFormat.
1510 *
1511 * @remark The API doesn't support formatting of floating point numbers at the moment.
1512 */
1513RTDECL(void) RTLogPrintfV(const char *pszFormat, va_list args);
1514
1515
1516#ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/string.h */
1517#define DECLARED_FNRTSTROUTPUT
1518/**
1519 * Output callback.
1520 *
1521 * @returns number of bytes written.
1522 * @param pvArg User argument.
1523 * @param pachChars Pointer to an array of utf-8 characters.
1524 * @param cbChars Number of bytes in the character array pointed to by pachChars.
1525 */
1526typedef DECLCALLBACK(size_t) FNRTSTROUTPUT(void *pvArg, const char *pachChars, size_t cbChars);
1527/** Pointer to callback function. */
1528typedef FNRTSTROUTPUT *PFNRTSTROUTPUT;
1529#endif
1530
1531/**
1532 * Partial vsprintf worker implementation.
1533 *
1534 * @returns number of bytes formatted.
1535 * @param pfnOutput Output worker.
1536 * Called in two ways. Normally with a string an it's length.
1537 * For termination, it's called with NULL for string, 0 for length.
1538 * @param pvArg Argument to output worker.
1539 * @param pszFormat Format string.
1540 * @param args Argument list.
1541 */
1542RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args);
1543
1544/**
1545 * Write log buffer to COM port.
1546 *
1547 * @param pach Pointer to the buffer to write.
1548 * @param cb Number of bytes to write.
1549 */
1550RTDECL(void) RTLogWriteCom(const char *pach, size_t cb);
1551
1552/**
1553 * Prints a formatted string to the serial port used for logging.
1554 *
1555 * @returns Number of bytes written.
1556 * @param pszFormat Format string.
1557 * @param ... Optional arguments specified in the format string.
1558 */
1559RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...);
1560
1561/**
1562 * Prints a formatted string to the serial port used for logging.
1563 *
1564 * @returns Number of bytes written.
1565 * @param pszFormat Format string.
1566 * @param args Optional arguments specified in the format string.
1567 */
1568RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args);
1569
1570
1571#if 0 /* not implemented yet */
1572
1573/** Indicates that the semaphores shall be used to notify the other
1574 * part about buffer changes. */
1575#define LOGHOOKBUFFER_FLAGS_SEMAPHORED 1
1576
1577/**
1578 * Log Hook Buffer.
1579 * Use to commuicate between the logger and a log consumer.
1580 */
1581typedef struct RTLOGHOOKBUFFER
1582{
1583 /** Write pointer. */
1584 volatile void *pvWrite;
1585 /** Read pointer. */
1586 volatile void *pvRead;
1587 /** Buffer start. */
1588 void *pvStart;
1589 /** Buffer end (exclusive). */
1590 void *pvEnd;
1591 /** Signaling semaphore used by the writer to wait on a full buffer.
1592 * Only used when indicated in flags. */
1593 void *pvSemWriter;
1594 /** Signaling semaphore used by the read to wait on an empty buffer.
1595 * Only used when indicated in flags. */
1596 void *pvSemReader;
1597 /** Buffer flags. Current reserved and set to zero. */
1598 volatile unsigned fFlags;
1599} RTLOGHOOKBUFFER;
1600/** Pointer to a log hook buffer. */
1601typedef RTLOGHOOKBUFFER *PRTLOGHOOKBUFFER;
1602
1603
1604/**
1605 * Register a logging hook.
1606 *
1607 * This type of logging hooks are expecting different threads acting
1608 * producer and consumer. They share a circular buffer which have two
1609 * pointers one for each end. When the buffer is full there are two
1610 * alternatives (indicated by a buffer flag), either wait for the
1611 * consumer to get it's job done, or to write a generic message saying
1612 * buffer overflow.
1613 *
1614 * Since the waiting would need a signal semaphore, we'll skip that for now.
1615 *
1616 * @returns iprt status code.
1617 * @param pBuffer Pointer to a logger hook buffer.
1618 */
1619RTDECL(int) RTLogRegisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
1620
1621/**
1622 * Deregister a logging hook registerd with RTLogRegisterHook().
1623 *
1624 * @returns iprt status code.
1625 * @param pBuffer Pointer to a logger hook buffer.
1626 */
1627RTDECL(int) RTLogDeregisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
1628
1629#endif /* not implemented yet */
1630
1631
1632
1633/**
1634 * Write log buffer to a debugger (RTLOGDEST_DEBUGGER).
1635 *
1636 * @param pach What to write.
1637 * @param cb How much to write.
1638 * @remark When linking statically, this function can be replaced by defining your own.
1639 */
1640RTDECL(void) RTLogWriteDebugger(const char *pach, size_t cb);
1641
1642/**
1643 * Write log buffer to a user defined output stream (RTLOGDEST_USER).
1644 *
1645 * @param pach What to write.
1646 * @param cb How much to write.
1647 * @remark When linking statically, this function can be replaced by defining your own.
1648 */
1649RTDECL(void) RTLogWriteUser(const char *pach, size_t cb);
1650
1651/**
1652 * Write log buffer to stdout (RTLOGDEST_STDOUT).
1653 *
1654 * @param pach What to write.
1655 * @param cb How much to write.
1656 * @remark When linking statically, this function can be replaced by defining your own.
1657 */
1658RTDECL(void) RTLogWriteStdOut(const char *pach, size_t cb);
1659
1660/**
1661 * Write log buffer to stdout (RTLOGDEST_STDERR).
1662 *
1663 * @param pach What to write.
1664 * @param cb How much to write.
1665 * @remark When linking statically, this function can be replaced by defining your own.
1666 */
1667RTDECL(void) RTLogWriteStdErr(const char *pach, size_t cb);
1668
1669#ifdef VBOX
1670
1671/**
1672 * Prints a formatted string to the backdoor port.
1673 *
1674 * @returns Number of bytes written.
1675 * @param pszFormat Format string.
1676 * @param ... Optional arguments specified in the format string.
1677 */
1678RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...);
1679
1680/**
1681 * Prints a formatted string to the backdoor port.
1682 *
1683 * @returns Number of bytes written.
1684 * @param pszFormat Format string.
1685 * @param args Optional arguments specified in the format string.
1686 */
1687RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args);
1688
1689#endif /* VBOX */
1690
1691__END_DECLS
1692
1693/** @} */
1694
1695#endif
1696
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