VirtualBox

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

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

Interface for generating NMI & SMI added.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette