VirtualBox

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

Last change on this file since 55989 was 55989, checked in by vboxsync, 10 years ago

iprt/log.h: Make RTLOGGRPFLAGS_FLOW and RTLOGGRPFLAGS_WARN be in the byte immediate range.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 84.9 KB
Line 
1/** @file
2 * IPRT - Logging.
3 */
4
5/*
6 * Copyright (C) 2006-2012 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_log_h
27#define ___iprt_log_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_rt_log RTLog - Logging
36 * @ingroup grp_rt
37 * @{
38 */
39
40/**
41 * IPRT Logging Groups.
42 * (Remember to update RT_LOGGROUP_NAMES!)
43 *
44 * @remark It should be pretty obvious, but just to have
45 * mentioned it, the values are sorted alphabetically (using the
46 * english alphabet) except for _DEFAULT which is always first.
47 *
48 * If anyone might be wondering what the alphabet looks like:
49 * a b c d e f g h i j k l m n o p q r s t u v w x y z
50 */
51typedef enum RTLOGGROUP
52{
53 /** Default logging group. */
54 RTLOGGROUP_DEFAULT,
55 RTLOGGROUP_DBG,
56 RTLOGGROUP_DBG_DWARF,
57 RTLOGGROUP_DIR,
58 RTLOGGROUP_FILE,
59 RTLOGGROUP_FS,
60 RTLOGGROUP_LDR,
61 RTLOGGROUP_PATH,
62 RTLOGGROUP_PROCESS,
63 RTLOGGROUP_SYMLINK,
64 RTLOGGROUP_THREAD,
65 RTLOGGROUP_TIME,
66 RTLOGGROUP_TIMER,
67 RTLOGGROUP_ZIP = 31,
68 RTLOGGROUP_FIRST_USER = 32
69} RTLOGGROUP;
70
71/** @def RT_LOGGROUP_NAMES
72 * IPRT Logging group names.
73 *
74 * Must correspond 100% to RTLOGGROUP!
75 * Don't forget commas!
76 *
77 * @remark It should be pretty obvious, but just to have
78 * mentioned it, the values are sorted alphabetically (using the
79 * english alphabet) except for _DEFAULT which is always first.
80 *
81 * If anyone might be wondering what the alphabet looks like:
82 * 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
83 */
84#define RT_LOGGROUP_NAMES \
85 "DEFAULT", \
86 "RT_DBG", \
87 "RT_DBG_DWARF", \
88 "RT_DIR", \
89 "RT_FILE", \
90 "RT_FS", \
91 "RT_LDR", \
92 "RT_PATH", \
93 "RT_PROCESS", \
94 "RT_SYMLINK", \
95 "RT_THREAD", \
96 "RT_TIME", \
97 "RT_TIMER", \
98 "RT_13", \
99 "RT_14", \
100 "RT_15", \
101 "RT_16", \
102 "RT_17", \
103 "RT_18", \
104 "RT_19", \
105 "RT_20", \
106 "RT_21", \
107 "RT_22", \
108 "RT_23", \
109 "RT_24", \
110 "RT_25", \
111 "RT_26", \
112 "RT_27", \
113 "RT_28", \
114 "RT_29", \
115 "RT_30", \
116 "RT_ZIP" \
117
118
119/** @def LOG_GROUP
120 * Active logging group.
121 */
122#ifndef LOG_GROUP
123# define LOG_GROUP RTLOGGROUP_DEFAULT
124#endif
125
126/** @def LOG_FN_FMT
127 * You can use this to specify you desired way of printing __PRETTY_FUNCTION__
128 * if you dislike the default one.
129 */
130#ifndef LOG_FN_FMT
131# define LOG_FN_FMT "%Rfn"
132#endif
133
134#ifdef LOG_INSTANCE
135# error "LOG_INSTANCE is no longer supported."
136#endif
137#ifdef LOG_REL_INSTANCE
138# error "LOG_REL_INSTANCE is no longer supported."
139#endif
140
141/** Logger structure. */
142#ifdef IN_RC
143typedef struct RTLOGGERRC RTLOGGER;
144#else
145typedef struct RTLOGGER RTLOGGER;
146#endif
147/** Pointer to logger structure. */
148typedef RTLOGGER *PRTLOGGER;
149/** Pointer to const logger structure. */
150typedef const RTLOGGER *PCRTLOGGER;
151
152
153/** Guest context logger structure. */
154typedef struct RTLOGGERRC RTLOGGERRC;
155/** Pointer to guest context logger structure. */
156typedef RTLOGGERRC *PRTLOGGERRC;
157/** Pointer to const guest context logger structure. */
158typedef const RTLOGGERRC *PCRTLOGGERRC;
159
160
161/**
162 * Logger phase.
163 *
164 * Used for signalling the log header/footer callback what to do.
165 */
166typedef enum RTLOGPHASE
167{
168 /** Begin of the logging. */
169 RTLOGPHASE_BEGIN = 0,
170 /** End of the logging. */
171 RTLOGPHASE_END,
172 /** Before rotating the log file. */
173 RTLOGPHASE_PREROTATE,
174 /** After rotating the log file. */
175 RTLOGPHASE_POSTROTATE,
176 /** 32-bit type blow up hack. */
177 RTLOGPHASE_32BIT_HACK = 0x7fffffff
178} RTLOGPHASE;
179
180
181/**
182 * Logger function.
183 *
184 * @param pszFormat Format string.
185 * @param ... Optional arguments as specified in the format string.
186 */
187typedef DECLCALLBACK(void) FNRTLOGGER(const char *pszFormat, ...);
188/** Pointer to logger function. */
189typedef FNRTLOGGER *PFNRTLOGGER;
190
191/**
192 * Flush function.
193 *
194 * @param pLogger Pointer to the logger instance which is to be flushed.
195 */
196typedef DECLCALLBACK(void) FNRTLOGFLUSH(PRTLOGGER pLogger);
197/** Pointer to flush function. */
198typedef FNRTLOGFLUSH *PFNRTLOGFLUSH;
199
200/**
201 * Flush function.
202 *
203 * @param pLogger Pointer to the logger instance which is to be flushed.
204 */
205typedef DECLCALLBACK(void) FNRTLOGFLUSHGC(PRTLOGGERRC pLogger);
206/** Pointer to logger function. */
207typedef RCPTRTYPE(FNRTLOGFLUSHGC *) PFNRTLOGFLUSHGC;
208
209/**
210 * Header/footer message callback.
211 *
212 * @param pLogger Pointer to the logger instance.
213 * @param pszFormat Format string.
214 * @param ... Optional arguments specified in the format string.
215 */
216typedef DECLCALLBACK(void) FNRTLOGPHASEMSG(PRTLOGGER pLogger, const char *pszFormat, ...);
217/** Pointer to header/footer message callback function. */
218typedef FNRTLOGPHASEMSG *PFNRTLOGPHASEMSG;
219
220/**
221 * Log file header/footer callback.
222 *
223 * @param pLogger Pointer to the logger instance.
224 * @param enmLogPhase Indicates at what time the callback is invoked.
225 * @param pfnLogPhaseMsg Callback for writing the header/footer (RTLogPrintf
226 * and others are out of bounds).
227 */
228typedef DECLCALLBACK(void) FNRTLOGPHASE(PRTLOGGER pLogger, RTLOGPHASE enmLogPhase, PFNRTLOGPHASEMSG pfnLogPhaseMsg);
229/** Pointer to log header/footer callback function. */
230typedef FNRTLOGPHASE *PFNRTLOGPHASE;
231
232/**
233 * Custom log prefix callback.
234 *
235 *
236 * @returns The number of chars written.
237 *
238 * @param pLogger Pointer to the logger instance.
239 * @param pchBuf Output buffer pointer.
240 * No need to terminate the output.
241 * @param cchBuf The size of the output buffer.
242 * @param pvUser The user argument.
243 */
244typedef DECLCALLBACK(size_t) FNRTLOGPREFIX(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
245/** Pointer to prefix callback function. */
246typedef FNRTLOGPREFIX *PFNRTLOGPREFIX;
247
248
249
250/**
251 * Logger instance structure for raw-mode context (RC).
252 */
253struct RTLOGGERRC
254{
255 /** Pointer to temporary scratch buffer.
256 * This is used to format the log messages. */
257 char achScratch[32768];
258 /** Current scratch buffer position. */
259 uint32_t offScratch;
260 /** This is set if a prefix is pending. */
261 bool fPendingPrefix;
262 bool afAlignment[3];
263 /** Pointer to the logger function.
264 * This is actually pointer to a wrapper which will push a pointer to the
265 * instance pointer onto the stack before jumping to the real logger function.
266 * A very unfortunate hack to work around the missing variadic macro support in C++. */
267 RCPTRTYPE(PFNRTLOGGER) pfnLogger;
268 /** Pointer to the flush function. */
269 PFNRTLOGFLUSHGC pfnFlush;
270 /** Magic number (RTLOGGERRC_MAGIC). */
271 uint32_t u32Magic;
272 /** Logger instance flags - RTLOGFLAGS. */
273 uint32_t fFlags;
274 /** Number of groups in the afGroups member. */
275 uint32_t 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 uint32_t afGroups[1];
280};
281
282/** RTLOGGERRC::u32Magic value. (John Rogers Searle) */
283#define RTLOGGERRC_MAGIC 0x19320731
284
285
286
287#ifndef IN_RC
288
289/** Pointer to internal logger bits. */
290typedef struct RTLOGGERINTERNAL *PRTLOGGERINTERNAL;
291
292/**
293 * Logger instance structure.
294 */
295struct RTLOGGER
296{
297 /** Pointer to temporary scratch buffer.
298 * This is used to format the log messages. */
299 char achScratch[49152];
300 /** Current scratch buffer position. */
301 uint32_t offScratch;
302 /** Magic number. */
303 uint32_t u32Magic;
304 /** Logger instance flags - RTLOGFLAGS. */
305 uint32_t fFlags;
306 /** Destination flags - RTLOGDEST. */
307 uint32_t fDestFlags;
308 /** Pointer to the internal bits of the logger.
309 * (The memory is allocated in the same block as RTLOGGER.) */
310 PRTLOGGERINTERNAL pInt;
311 /** Pointer to the logger function (used in non-C99 mode only).
312 *
313 * This is actually pointer to a wrapper which will push a pointer to the
314 * instance pointer onto the stack before jumping to the real logger function.
315 * A very unfortunate hack to work around the missing variadic macro
316 * support in older C++/C standards. (The memory is allocated using
317 * RTMemExecAlloc(), except for agnostic R0 code.) */
318 PFNRTLOGGER pfnLogger;
319 /** Number of groups in the afGroups and papszGroups members. */
320 uint32_t cGroups;
321 /** Group flags array - RTLOGGRPFLAGS.
322 * This member have variable length and may extend way beyond
323 * the declared size of 1 entry. */
324 uint32_t afGroups[1];
325};
326
327/** RTLOGGER::u32Magic value. (Avram Noam Chomsky) */
328# define RTLOGGER_MAGIC UINT32_C(0x19281207)
329
330#endif /* !IN_RC */
331
332
333/**
334 * Logger flags.
335 */
336typedef enum RTLOGFLAGS
337{
338 /** The logger instance is disabled for normal output. */
339 RTLOGFLAGS_DISABLED = 0x00000001,
340 /** The logger instance is using buffered output. */
341 RTLOGFLAGS_BUFFERED = 0x00000002,
342 /** The logger instance expands LF to CR/LF. */
343 RTLOGFLAGS_USECRLF = 0x00000010,
344 /** Append to the log destination where applicable. */
345 RTLOGFLAGS_APPEND = 0x00000020,
346 /** Show relative timestamps with PREFIX_TSC and PREFIX_TS */
347 RTLOGFLAGS_REL_TS = 0x00000040,
348 /** Show decimal timestamps with PREFIX_TSC and PREFIX_TS */
349 RTLOGFLAGS_DECIMAL_TS = 0x00000080,
350 /** Open the file in write through mode. */
351 RTLOGFLAGS_WRITE_THROUGH = 0x00000100,
352 /** Flush the file to disk when flushing the buffer. */
353 RTLOGFLAGS_FLUSH = 0x00000200,
354 /** Restrict the number of log entries per group. */
355 RTLOGFLAGS_RESTRICT_GROUPS = 0x00000400,
356 /** New lines should be prefixed with the write and read lock counts. */
357 RTLOGFLAGS_PREFIX_LOCK_COUNTS = 0x00008000,
358 /** New lines should be prefixed with the CPU id (ApicID on intel/amd). */
359 RTLOGFLAGS_PREFIX_CPUID = 0x00010000,
360 /** New lines should be prefixed with the native process id. */
361 RTLOGFLAGS_PREFIX_PID = 0x00020000,
362 /** New lines should be prefixed with group flag number causing the output. */
363 RTLOGFLAGS_PREFIX_FLAG_NO = 0x00040000,
364 /** New lines should be prefixed with group flag name causing the output. */
365 RTLOGFLAGS_PREFIX_FLAG = 0x00080000,
366 /** New lines should be prefixed with group number. */
367 RTLOGFLAGS_PREFIX_GROUP_NO = 0x00100000,
368 /** New lines should be prefixed with group name. */
369 RTLOGFLAGS_PREFIX_GROUP = 0x00200000,
370 /** New lines should be prefixed with the native thread id. */
371 RTLOGFLAGS_PREFIX_TID = 0x00400000,
372 /** New lines should be prefixed with thread name. */
373 RTLOGFLAGS_PREFIX_THREAD = 0x00800000,
374 /** New lines should be prefixed with data from a custom callback. */
375 RTLOGFLAGS_PREFIX_CUSTOM = 0x01000000,
376 /** New lines should be prefixed with formatted timestamp since program start. */
377 RTLOGFLAGS_PREFIX_TIME_PROG = 0x04000000,
378 /** New lines should be prefixed with formatted timestamp (UCT). */
379 RTLOGFLAGS_PREFIX_TIME = 0x08000000,
380 /** New lines should be prefixed with milliseconds since program start. */
381 RTLOGFLAGS_PREFIX_MS_PROG = 0x10000000,
382 /** New lines should be prefixed with timestamp. */
383 RTLOGFLAGS_PREFIX_TSC = 0x20000000,
384 /** New lines should be prefixed with timestamp. */
385 RTLOGFLAGS_PREFIX_TS = 0x40000000,
386 /** The prefix mask. */
387 RTLOGFLAGS_PREFIX_MASK = 0x7dff8000
388} RTLOGFLAGS;
389
390/**
391 * Logger per group flags.
392 *
393 * @remarks We only use the lower 16 bits here. We'll be combining it with the
394 * group number in a few places.
395 */
396typedef enum RTLOGGRPFLAGS
397{
398 /** Enabled. */
399 RTLOGGRPFLAGS_ENABLED = 0x0001,
400 /** Flow logging. */
401 RTLOGGRPFLAGS_FLOW = 0x0002,
402 /** Warnings logging. */
403 RTLOGGRPFLAGS_WARN = 0x0004,
404 /* 0x0008 for later. */
405 /** Level 1 logging. */
406 RTLOGGRPFLAGS_LEVEL_1 = 0x0010,
407 /** Level 2 logging. */
408 RTLOGGRPFLAGS_LEVEL_2 = 0x0020,
409 /** Level 3 logging. */
410 RTLOGGRPFLAGS_LEVEL_3 = 0x0040,
411 /** Level 4 logging. */
412 RTLOGGRPFLAGS_LEVEL_4 = 0x0080,
413 /** Level 5 logging. */
414 RTLOGGRPFLAGS_LEVEL_5 = 0x0100,
415 /** Level 6 logging. */
416 RTLOGGRPFLAGS_LEVEL_6 = 0x0200,
417 /** Level 7 logging. */
418 RTLOGGRPFLAGS_LEVEL_7 = 0x0400,
419 /** Level 8 logging. */
420 RTLOGGRPFLAGS_LEVEL_8 = 0x0800,
421 /** Level 9 logging. */
422 RTLOGGRPFLAGS_LEVEL_9 = 0x1000,
423 /** Level 10 logging. */
424 RTLOGGRPFLAGS_LEVEL_10 = 0x2000,
425 /** Level 11 logging. */
426 RTLOGGRPFLAGS_LEVEL_11 = 0x4000,
427 /** Level 12 logging. */
428 RTLOGGRPFLAGS_LEVEL_12 = 0x8000,
429
430 /** Restrict the number of log entries. */
431 RTLOGGRPFLAGS_RESTRICT = 0x40000000,
432 /** Blow up the type. */
433 RTLOGGRPFLAGS_32BIT_HACK = 0x7fffffff
434} RTLOGGRPFLAGS;
435
436/**
437 * Logger destination type.
438 */
439typedef enum RTLOGDEST
440{
441 /** Log to file. */
442 RTLOGDEST_FILE = 0x00000001,
443 /** Log to stdout. */
444 RTLOGDEST_STDOUT = 0x00000002,
445 /** Log to stderr. */
446 RTLOGDEST_STDERR = 0x00000004,
447 /** Log to debugger (win32 only). */
448 RTLOGDEST_DEBUGGER = 0x00000008,
449 /** Log to com port. */
450 RTLOGDEST_COM = 0x00000010,
451 /** Log a memory ring buffer. */
452 RTLOGDEST_RINGBUF = 0x00000020,
453 /** Just a dummy flag to be used when no other flag applies. */
454 RTLOGDEST_DUMMY = 0x20000000,
455 /** Log to a user defined output stream. */
456 RTLOGDEST_USER = 0x40000000
457} RTLOGDEST;
458
459
460RTDECL(void) RTLogPrintfEx(void *pvInstance, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
461
462
463#ifdef DOXYGEN_RUNNING
464# define LOG_DISABLED
465# define LOG_ENABLED
466# define LOG_ENABLE_FLOW
467#endif
468
469/** @def LOG_DISABLED
470 * Use this compile time define to disable all logging macros. It can
471 * be overridden for each of the logging macros by the LOG_ENABLE*
472 * compile time defines.
473 */
474
475/** @def LOG_ENABLED
476 * Use this compile time define to enable logging when not in debug mode
477 * or LOG_DISABLED is set.
478 * This will enabled Log() only.
479 */
480
481/** @def LOG_ENABLE_FLOW
482 * Use this compile time define to enable flow logging when not in
483 * debug mode or LOG_DISABLED is defined.
484 * This will enable LogFlow() only.
485 */
486
487/*
488 * Determine whether logging is enabled and forcefully normalize the indicators.
489 */
490#if (defined(DEBUG) || defined(LOG_ENABLED)) && !defined(LOG_DISABLED)
491# undef LOG_DISABLED
492# undef LOG_ENABLED
493# define LOG_ENABLED
494#else
495# undef LOG_ENABLED
496# undef LOG_DISABLED
497# define LOG_DISABLED
498#endif
499
500
501/** @def LOG_USE_C99
502 * Governs the use of variadic macros.
503 */
504#ifndef LOG_USE_C99
505# if defined(RT_ARCH_AMD64) || defined(RT_OS_DARWIN) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
506# define LOG_USE_C99
507# endif
508#endif
509
510
511/** @name Macros for checking whether a log level is enabled.
512 * @{ */
513/** @def LogIsItEnabled
514 * Checks whether the specified logging group is enabled or not.
515 */
516#ifdef LOG_ENABLED
517# define LogIsItEnabled(a_fFlags, a_iGroup) ( RTLogDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)) != NULL )
518#else
519# define LogIsItEnabled(a_fFlags, a_iGroup) (false)
520#endif
521
522/** @def LogIsEnabled
523 * Checks whether level 1 logging is enabled.
524 */
525#define LogIsEnabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP)
526
527/** @def LogIs2Enabled
528 * Checks whether level 2 logging is enabled.
529 */
530#define LogIs2Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP)
531
532/** @def LogIs3Enabled
533 * Checks whether level 3 logging is enabled.
534 */
535#define LogIs3Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP)
536
537/** @def LogIs4Enabled
538 * Checks whether level 4 logging is enabled.
539 */
540#define LogIs4Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP)
541
542/** @def LogIs5Enabled
543 * Checks whether level 5 logging is enabled.
544 */
545#define LogIs5Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP)
546
547/** @def LogIs6Enabled
548 * Checks whether level 6 logging is enabled.
549 */
550#define LogIs6Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP)
551
552/** @def LogIs7Enabled
553 * Checks whether level 7 logging is enabled.
554 */
555#define LogIs7Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP)
556
557/** @def LogIs8Enabled
558 * Checks whether level 8 logging is enabled.
559 */
560#define LogIs8Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP)
561
562/** @def LogIs9Enabled
563 * Checks whether level 9 logging is enabled.
564 */
565#define LogIs9Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP)
566
567/** @def LogIs10Enabled
568 * Checks whether level 10 logging is enabled.
569 */
570#define LogIs10Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP)
571
572/** @def LogIs11Enabled
573 * Checks whether level 11 logging is enabled.
574 */
575#define LogIs11Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP)
576
577/** @def LogIs12Enabled
578 * Checks whether level 12 logging is enabled.
579 */
580#define LogIs12Enabled() LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP)
581
582/** @def LogIsFlowEnabled
583 * Checks whether execution flow logging is enabled.
584 */
585#define LogIsFlowEnabled() LogIsItEnabled(RTLOGGRPFLAGS_FLOW, LOG_GROUP)
586
587/** @def LogIsWarnEnabled
588 * Checks whether execution flow logging is enabled.
589 */
590#define LogIsWarnEnabled() LogIsItEnabled(RTLOGGRPFLAGS_WARN, LOG_GROUP)
591/** @} */
592
593
594/** @def LogIt
595 * Write to specific logger if group enabled.
596 */
597#ifdef LOG_ENABLED
598# if defined(LOG_USE_C99)
599# define _LogRemoveParentheseis(...) __VA_ARGS__
600# define _LogIt(a_fFlags, a_iGroup, ...) \
601 do \
602 { \
603 register PRTLOGGER LogIt_pLogger = RTLogDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
604 if (RT_LIKELY(!LogIt_pLogger)) \
605 { /* likely */ } \
606 else \
607 RTLogLoggerEx(LogIt_pLogger, a_fFlags, a_iGroup, __VA_ARGS__); \
608 } while (0)
609# define LogIt(a_fFlags, a_iGroup, fmtargs) _LogIt(a_fFlags, a_iGroup, _LogRemoveParentheseis fmtargs)
610# define _LogItAlways(a_fFlags, a_iGroup, ...) RTLogLoggerEx(NULL, a_fFlags, UINT32_MAX, __VA_ARGS__)
611# define LogItAlways(a_fFlags, a_iGroup, fmtargs) _LogItAlways(a_fFlags, a_iGroup, _LogRemoveParentheseis fmtargs)
612 /** @todo invent a flag or something for skipping the group check so we can pass iGroup. LogItAlways. */
613# else
614# define LogIt(a_fFlags, a_iGroup, fmtargs) \
615 do \
616 { \
617 register PRTLOGGER LogIt_pLogger = RTLogDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
618 if (RT_LIKELY(!LogIt_pLogger)) \
619 { /* likely */ } \
620 else \
621 { \
622 LogIt_pLogger->pfnLogger fmtargs; \
623 } \
624 } while (0)
625# define LogItAlways(a_fFlags, a_iGroup, fmtargs) \
626 do \
627 { \
628 register PRTLOGGER LogIt_pLogger = RTLogDefaultInstanceEx(RT_MAKE_U32(0, UINT16_MAX)); \
629 if (LogIt_pLogger) \
630 LogIt_pLogger->pfnLogger fmtargs; \
631 } while (0)
632# endif
633#else
634# define LogIt(a_fFlags, a_iGroup, fmtargs) do { } while (0)
635# define LogItAlways(a_fFlags, a_iGroup, fmtargs) do { } while (0)
636# if defined(LOG_USE_C99)
637# define _LogRemoveParentheseis(...) __VA_ARGS__
638# define _LogIt(a_fFlags, a_iGroup, ...) do { } while (0)
639# define _LogItAlways(a_fFlags, a_iGroup, ...) do { } while (0)
640# endif
641#endif
642
643
644/** @name Basic logging macros
645 * @{ */
646/** @def Log
647 * Level 1 logging that works regardless of the group settings.
648 */
649#define LogAlways(a) LogItAlways(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
650
651/** @def Log
652 * Level 1 logging.
653 */
654#define Log(a) LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
655
656/** @def Log2
657 * Level 2 logging.
658 */
659#define Log2(a) LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, a)
660
661/** @def Log3
662 * Level 3 logging.
663 */
664#define Log3(a) LogIt(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, a)
665
666/** @def Log4
667 * Level 4 logging.
668 */
669#define Log4(a) LogIt(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, a)
670
671/** @def Log5
672 * Level 5 logging.
673 */
674#define Log5(a) LogIt(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, a)
675
676/** @def Log6
677 * Level 6 logging.
678 */
679#define Log6(a) LogIt(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, a)
680
681/** @def Log7
682 * Level 7 logging.
683 */
684#define Log7(a) LogIt(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP, a)
685
686/** @def Log8
687 * Level 8 logging.
688 */
689#define Log8(a) LogIt(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP, a)
690
691/** @def Log9
692 * Level 9 logging.
693 */
694#define Log9(a) LogIt(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP, a)
695
696/** @def Log10
697 * Level 10 logging.
698 */
699#define Log10(a) LogIt(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP, a)
700
701/** @def Log11
702 * Level 11 logging.
703 */
704#define Log11(a) LogIt(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP, a)
705
706/** @def Log12
707 * Level 12 logging.
708 */
709#define Log12(a) LogIt(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP, a)
710
711/** @def LogFlow
712 * Logging of execution flow.
713 */
714#define LogFlow(a) LogIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP, a)
715
716/** @def LogWarn
717 * Logging of warnings.
718 */
719#define LogWarn(a) LogIt(RTLOGGRPFLAGS_WARN, LOG_GROUP, a)
720/** @} */
721
722
723/** @name Logging macros prefixing the current function name.
724 * @{ */
725/** @def LogFunc
726 * Level 1 logging inside C/C++ functions.
727 *
728 * Prepends the given log message with the function name followed by a
729 * semicolon and space.
730 *
731 * @param a Log message in format <tt>("string\n" [, args])</tt>.
732 */
733#ifdef LOG_USE_C99
734# define LogFunc(a) _LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
735#else
736# define LogFunc(a) do { Log((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log(a); } while (0)
737#endif
738
739/** @def Log2Func
740 * Level 2 logging inside C/C++ functions.
741 *
742 * Prepends the given log message with the function name followed by a
743 * semicolon and space.
744 *
745 * @param a Log message in format <tt>("string\n" [, args])</tt>.
746 */
747#ifdef LOG_USE_C99
748# define Log2Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
749#else
750# define Log2Func(a) do { Log2((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log2(a); } while (0)
751#endif
752
753/** @def Log3Func
754 * Level 3 logging inside C/C++ functions.
755 *
756 * Prepends the given log message with the function name followed by a
757 * semicolon and space.
758 *
759 * @param a Log message in format <tt>("string\n" [, args])</tt>.
760 */
761#ifdef LOG_USE_C99
762# define Log3Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
763#else
764# define Log3Func(a) do { Log3((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log3(a); } while (0)
765#endif
766
767/** @def Log4Func
768 * Level 4 logging inside C/C++ functions.
769 *
770 * Prepends the given log message with the function name followed by a
771 * semicolon and space.
772 *
773 * @param a Log message in format <tt>("string\n" [, args])</tt>.
774 */
775#ifdef LOG_USE_C99
776# define Log4Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
777#else
778# define Log4Func(a) do { Log4((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log4(a); } while (0)
779#endif
780
781/** @def Log5Func
782 * Level 5 logging inside C/C++ functions.
783 *
784 * Prepends the given log message with the function name followed by a
785 * semicolon and space.
786 *
787 * @param a Log message in format <tt>("string\n" [, args])</tt>.
788 */
789#ifdef LOG_USE_C99
790# define Log5Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
791#else
792# define Log5Func(a) do { Log5((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log5(a); } while (0)
793#endif
794
795/** @def Log6Func
796 * Level 6 logging inside C/C++ functions.
797 *
798 * Prepends the given log message with the function name followed by a
799 * semicolon and space.
800 *
801 * @param a Log message in format <tt>("string\n" [, args])</tt>.
802 */
803#ifdef LOG_USE_C99
804# define Log6Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
805#else
806# define Log6Func(a) do { Log6((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log6(a); } while (0)
807#endif
808
809/** @def Log7Func
810 * Level 7 logging inside C/C++ functions.
811 *
812 * Prepends the given log message with the function name followed by a
813 * semicolon and space.
814 *
815 * @param a Log message in format <tt>("string\n" [, args])</tt>.
816 */
817#ifdef LOG_USE_C99
818# define Log7Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
819#else
820# define Log7Func(a) do { Log7((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log7(a); } while (0)
821#endif
822
823/** @def Log8Func
824 * Level 8 logging inside C/C++ functions.
825 *
826 * Prepends the given log message with the function name followed by a
827 * semicolon and space.
828 *
829 * @param a Log message in format <tt>("string\n" [, args])</tt>.
830 */
831#ifdef LOG_USE_C99
832# define Log8Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
833#else
834# define Log8Func(a) do { Log8((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log8(a); } while (0)
835#endif
836
837/** @def Log9Func
838 * Level 9 logging inside C/C++ functions.
839 *
840 * Prepends the given log message with the function name followed by a
841 * semicolon and space.
842 *
843 * @param a Log message in format <tt>("string\n" [, args])</tt>.
844 */
845#ifdef LOG_USE_C99
846# define Log9Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
847#else
848# define Log9Func(a) do { Log9((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log9(a); } while (0)
849#endif
850
851/** @def Log10Func
852 * Level 10 logging inside C/C++ functions.
853 *
854 * Prepends the given log message with the function name followed by a
855 * semicolon and space.
856 *
857 * @param a Log message in format <tt>("string\n" [, args])</tt>.
858 */
859#ifdef LOG_USE_C99
860# define Log10Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
861#else
862# define Log10Func(a) do { Log10((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log10(a); } while (0)
863#endif
864
865/** @def Log11Func
866 * Level 11 logging inside C/C++ functions.
867 *
868 * Prepends the given log message with the function name followed by a
869 * semicolon and space.
870 *
871 * @param a Log message in format <tt>("string\n" [, args])</tt>.
872 */
873#ifdef LOG_USE_C99
874# define Log11Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
875#else
876# define Log11Func(a) do { Log11((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log11(a); } while (0)
877#endif
878
879/** @def Log12Func
880 * Level 12 logging inside C/C++ functions.
881 *
882 * Prepends the given log message with the function name followed by a
883 * semicolon and space.
884 *
885 * @param a Log message in format <tt>("string\n" [, args])</tt>.
886 */
887#ifdef LOG_USE_C99
888# define Log12Func(a) _LogIt(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
889#else
890# define Log12Func(a) do { Log12((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); Log12(a); } while (0)
891#endif
892
893/** @def LogFlowFunc
894 * Macro to log the execution flow inside C/C++ functions.
895 *
896 * Prepends the given log message with the function name followed by
897 * a semicolon and space.
898 *
899 * @param a Log message in format <tt>("string\n" [, args])</tt>.
900 */
901#ifdef LOG_USE_C99
902# define LogFlowFunc(a) \
903 _LogIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
904#else
905# define LogFlowFunc(a) \
906 do { LogFlow((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
907#endif
908
909/** @def LogWarnFunc
910 * Macro to log a warning inside C/C++ functions.
911 *
912 * Prepends the given log message with the function name followed by
913 * a semicolon and space.
914 *
915 * @param a Log message in format <tt>("string\n" [, args])</tt>.
916 */
917#ifdef LOG_USE_C99
918# define LogWarnFunc(a) \
919 _LogIt(RTLOGGRPFLAGS_WARN, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
920#else
921# define LogWarnFunc(a) \
922 do { LogFlow((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
923#endif
924/** @} */
925
926
927/** @name Logging macros prefixing the this pointer value and method name.
928 * @{ */
929
930/** @def LogThisFunc
931 * Level 1 logging inside a C++ non-static method, with object pointer and
932 * method name prefixed to the given message.
933 * @param a Log message in format <tt>("string\n" [, args])</tt>.
934 */
935#ifdef LOG_USE_C99
936# define LogThisFunc(a) \
937 _LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
938#else
939# define LogThisFunc(a) do { Log(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log(a); } while (0)
940#endif
941
942/** @def Log2ThisFunc
943 * Level 2 logging inside a C++ non-static method, with object pointer and
944 * method name prefixed to the given message.
945 * @param a Log message in format <tt>("string\n" [, args])</tt>.
946 */
947#ifdef LOG_USE_C99
948# define Log2ThisFunc(a) \
949 _LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
950#else
951# define Log2ThisFunc(a) do { Log2(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log2(a); } while (0)
952#endif
953
954/** @def Log3ThisFunc
955 * Level 3 logging inside a C++ non-static method, with object pointer and
956 * method name prefixed to the given message.
957 * @param a Log message in format <tt>("string\n" [, args])</tt>.
958 */
959#ifdef LOG_USE_C99
960# define Log3ThisFunc(a) \
961 _LogIt(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
962#else
963# define Log3ThisFunc(a) do { Log3(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log3(a); } while (0)
964#endif
965
966/** @def Log4ThisFunc
967 * Level 4 logging inside a C++ non-static method, with object pointer and
968 * method name prefixed to the given message.
969 * @param a Log message in format <tt>("string\n" [, args])</tt>.
970 */
971#ifdef LOG_USE_C99
972# define Log4ThisFunc(a) \
973 _LogIt(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
974#else
975# define Log4ThisFunc(a) do { Log4(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log4(a); } while (0)
976#endif
977
978/** @def Log5ThisFunc
979 * Level 5 logging inside a C++ non-static method, with object pointer and
980 * method name prefixed to the given message.
981 * @param a Log message in format <tt>("string\n" [, args])</tt>.
982 */
983#ifdef LOG_USE_C99
984# define Log5ThisFunc(a) \
985 _LogIt(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
986#else
987# define Log5ThisFunc(a) do { Log5(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log5(a); } while (0)
988#endif
989
990/** @def Log6ThisFunc
991 * Level 6 logging inside a C++ non-static method, with object pointer and
992 * method name prefixed to the given message.
993 * @param a Log message in format <tt>("string\n" [, args])</tt>.
994 */
995#ifdef LOG_USE_C99
996# define Log6ThisFunc(a) \
997 _LogIt(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
998#else
999# define Log6ThisFunc(a) do { Log6(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log6(a); } while (0)
1000#endif
1001
1002/** @def Log7ThisFunc
1003 * Level 7 logging inside a C++ non-static method, with object pointer and
1004 * method name prefixed to the given message.
1005 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1006 */
1007#ifdef LOG_USE_C99
1008# define Log7ThisFunc(a) \
1009 _LogIt(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1010#else
1011# define Log7ThisFunc(a) do { Log7(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log7(a); } while (0)
1012#endif
1013
1014/** @def Log8ThisFunc
1015 * Level 8 logging inside a C++ non-static method, with object pointer and
1016 * method name prefixed to the given message.
1017 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1018 */
1019#ifdef LOG_USE_C99
1020# define Log8ThisFunc(a) \
1021 _LogIt(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1022#else
1023# define Log8ThisFunc(a) do { Log8(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log8(a); } while (0)
1024#endif
1025
1026/** @def Log9ThisFunc
1027 * Level 9 logging inside a C++ non-static method, with object pointer and
1028 * method name prefixed to the given message.
1029 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1030 */
1031#ifdef LOG_USE_C99
1032# define Log9ThisFunc(a) \
1033 _LogIt(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1034#else
1035# define Log9ThisFunc(a) do { Log9(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log9(a); } while (0)
1036#endif
1037
1038/** @def Log10ThisFunc
1039 * Level 10 logging inside a C++ non-static method, with object pointer and
1040 * method name prefixed to the given message.
1041 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1042 */
1043#ifdef LOG_USE_C99
1044# define Log10ThisFunc(a) \
1045 _LogIt(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1046#else
1047# define Log10ThisFunc(a) do { Log10(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log10(a); } while (0)
1048#endif
1049
1050/** @def Log11ThisFunc
1051 * Level 11 logging inside a C++ non-static method, with object pointer and
1052 * method name prefixed to the given message.
1053 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1054 */
1055#ifdef LOG_USE_C99
1056# define Log11ThisFunc(a) \
1057 _LogIt(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1058#else
1059# define Log11ThisFunc(a) do { Log11(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log11(a); } while (0)
1060#endif
1061
1062/** @def Log12ThisFunc
1063 * Level 12 logging inside a C++ non-static method, with object pointer and
1064 * method name prefixed to the given message.
1065 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1066 */
1067#ifdef LOG_USE_C99
1068# define Log12ThisFunc(a) \
1069 _LogIt(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1070#else
1071# define Log12ThisFunc(a) do { Log12(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); Log12(a); } while (0)
1072#endif
1073
1074/** @def LogFlowThisFunc
1075 * Flow level logging inside a C++ non-static method, with object pointer and
1076 * method name prefixed to the given message.
1077 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1078 */
1079#ifdef LOG_USE_C99
1080# define LogFlowThisFunc(a) \
1081 _LogIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1082#else
1083# define LogFlowThisFunc(a) do { LogFlow(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
1084#endif
1085
1086/** @def LogWarnThisFunc
1087 * Warning level logging inside a C++ non-static method, with object pointer and
1088 * method name prefixed to the given message.
1089 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1090 */
1091#ifdef LOG_USE_C99
1092# define LogWarnThisFunc(a) \
1093 _LogIt(RTLOGGRPFLAGS_WARN, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1094#else
1095# define LogWarnThisFunc(a) do { LogWarn(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogWarn(a); } while (0)
1096#endif
1097/** @} */
1098
1099
1100/** @name Misc Logging Macros
1101 * @{ */
1102
1103/** @def LogWarning1
1104 * The same as Log(), but prepents a <tt>"WARNING! "</tt> string to the message.
1105 *
1106 * @param a Custom log message in format <tt>("string\n" [, args])</tt>.
1107 */
1108#if defined(LOG_USE_C99)
1109# define Log1Warning(a) _LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "WARNING! %M", _LogRemoveParentheseis a )
1110#else
1111# define Log1Warning(a) do { Log(("WARNING! ")); Log(a); } while (0)
1112#endif
1113
1114/** @def LogWarningFunc
1115 * The same as LogWarning(), but prepents the log message with the function name.
1116 *
1117 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1118 */
1119#ifdef LOG_USE_C99
1120# define Log1WarningFunc(a) \
1121 _LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": WARNING! %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1122#else
1123# define Log1WarningFunc(a) \
1124 do { Log((LOG_FN_FMT ": WARNING! ", __PRETTY_FUNCTION__)); Log(a); } while (0)
1125#endif
1126
1127/** @def LogWarningThisFunc
1128 * The same as LogWarningFunc() but for class functions (methods): the resulting
1129 * log line is additionally prepended with a hex value of |this| pointer.
1130 *
1131 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1132 */
1133#ifdef LOG_USE_C99
1134# define Log1WarningThisFunc(a) \
1135 _LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": WARNING! %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1136#else
1137# define Log1WarningThisFunc(a) \
1138 do { Log(("{%p} " LOG_FN_FMT ": WARNING! ", this, __PRETTY_FUNCTION__)); Log(a); } while (0)
1139#endif
1140
1141
1142/** Shortcut to |LogFlowFunc ("ENTER\n")|, marks the beginnig of the function. */
1143#define LogFlowFuncEnter() LogFlowFunc(("ENTER\n"))
1144
1145/** Shortcut to |LogFlowFunc ("LEAVE\n")|, marks the end of the function. */
1146#define LogFlowFuncLeave() LogFlowFunc(("LEAVE\n"))
1147
1148/** Shortcut to |LogFlowFunc ("LEAVE: %Rrc\n")|, marks the end of the function. */
1149#define LogFlowFuncLeaveRC(rc) LogFlowFunc(("LEAVE: %Rrc\n", (rc)))
1150
1151/** Shortcut to |LogFlowThisFunc ("ENTER\n")|, marks the beginnig of the function. */
1152#define LogFlowThisFuncEnter() LogFlowThisFunc(("ENTER\n"))
1153
1154/** Shortcut to |LogFlowThisFunc ("LEAVE\n")|, marks the end of the function. */
1155#define LogFlowThisFuncLeave() LogFlowThisFunc(("LEAVE\n"))
1156
1157
1158/** @def LogObjRefCnt
1159 * Helper macro to print the current reference count of the given COM object
1160 * to the log file.
1161 *
1162 * @param pObj Pointer to the object in question (must be a pointer to an
1163 * IUnknown subclass or simply define COM-style AddRef() and
1164 * Release() methods)
1165 */
1166#define LogObjRefCnt(pObj) \
1167 do { \
1168 if (LogIsFlowEnabled()) \
1169 { \
1170 int cRefsForLog = (pObj)->AddRef(); \
1171 LogFlow((#pObj "{%p}.refCnt=%d\n", (pObj), cRefsForLog - 1)); \
1172 (pObj)->Release(); \
1173 } \
1174 } while (0)
1175/** @} */
1176
1177
1178
1179/** @name Passing Function Call Position When Logging.
1180 *
1181 * This is a little bit ugly as we have to omit the comma before the
1182 * position parameters so that we don't inccur any overhead in non-logging
1183 * builds (!defined(LOG_ENABLED).
1184 *
1185 * @{ */
1186/** Source position for passing to a function call. */
1187#ifdef LOG_ENABLED
1188# define RTLOG_COMMA_SRC_POS , __FILE__, __LINE__, __PRETTY_FUNCTION__
1189#else
1190# define RTLOG_COMMA_SRC_POS RT_NOTHING
1191#endif
1192/** Source position declaration. */
1193#ifdef LOG_ENABLED
1194# define RTLOG_COMMA_SRC_POS_DECL , const char *pszFile, unsigned iLine, const char *pszFunction
1195#else
1196# define RTLOG_COMMA_SRC_POS_DECL RT_NOTHING
1197#endif
1198/** Source position arguments. */
1199#ifdef LOG_ENABLED
1200# define RTLOG_COMMA_SRC_POS_ARGS , pszFile, iLine, pszFunction
1201#else
1202# define RTLOG_COMMA_SRC_POS_ARGS RT_NOTHING
1203#endif
1204/** Applies NOREF() to the source position arguments. */
1205#ifdef LOG_ENABLED
1206# define RTLOG_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
1207#else
1208# define RTLOG_SRC_POS_NOREF() do { } while (0)
1209#endif
1210/** @} */
1211
1212
1213
1214/** @name Release Logging
1215 * @{
1216 */
1217
1218#ifdef DOXYGEN_RUNNING
1219# define RTLOG_REL_DISABLED
1220# define RTLOG_REL_ENABLED
1221#endif
1222
1223/** @def RTLOG_REL_DISABLED
1224 * Use this compile time define to disable all release logging
1225 * macros.
1226 */
1227
1228/** @def RTLOG_REL_ENABLED
1229 * Use this compile time define to override RTLOG_REL_DISABLE.
1230 */
1231
1232/*
1233 * Determine whether release logging is enabled and forcefully normalize the indicators.
1234 */
1235#if !defined(RTLOG_REL_DISABLED) || defined(RTLOG_REL_ENABLED)
1236# undef RTLOG_REL_DISABLED
1237# undef RTLOG_REL_ENABLED
1238# define RTLOG_REL_ENABLED
1239#else
1240# undef RTLOG_REL_ENABLED
1241# undef RTLOG_REL_DISABLED
1242# define RTLOG_REL_DISABLED
1243#endif
1244
1245/** @name Macros for checking whether a release log level is enabled.
1246 * @{ */
1247/** @def LogRelIsItEnabled
1248 * Checks whether the specified release logging group is enabled or not.
1249 */
1250#define LogRelIsItEnabled(a_fFlags, a_iGroup) ( RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)) != NULL )
1251
1252/** @def LogRelIsEnabled
1253 * Checks whether level 1 release logging is enabled.
1254 */
1255#define LogRelIsEnabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP)
1256
1257/** @def LogRelIs2Enabled
1258 * Checks whether level 2 release logging is enabled.
1259 */
1260#define LogRelIs2Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP)
1261
1262/** @def LogRelIs3Enabled
1263 * Checks whether level 3 release logging is enabled.
1264 */
1265#define LogRelIs3Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP)
1266
1267/** @def LogRelIs4Enabled
1268 * Checks whether level 4 release logging is enabled.
1269 */
1270#define LogRelIs4Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP)
1271
1272/** @def LogRelIs5Enabled
1273 * Checks whether level 5 release logging is enabled.
1274 */
1275#define LogRelIs5Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP)
1276
1277/** @def LogRelIs6Enabled
1278 * Checks whether level 6 release logging is enabled.
1279 */
1280#define LogRelIs6Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP)
1281
1282/** @def LogRelIs7Enabled
1283 * Checks whether level 7 release logging is enabled.
1284 */
1285#define LogRelIs7Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP)
1286
1287/** @def LogRelIs8Enabled
1288 * Checks whether level 8 release logging is enabled.
1289 */
1290#define LogRelIs8Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP)
1291
1292/** @def LogRelIs2Enabled
1293 * Checks whether level 9 release logging is enabled.
1294 */
1295#define LogRelIs9Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP)
1296
1297/** @def LogRelIs10Enabled
1298 * Checks whether level 10 release logging is enabled.
1299 */
1300#define LogRelIs10Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP)
1301
1302/** @def LogRelIs11Enabled
1303 * Checks whether level 10 release logging is enabled.
1304 */
1305#define LogRelIs11Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP)
1306
1307/** @def LogRelIs12Enabled
1308 * Checks whether level 12 release logging is enabled.
1309 */
1310#define LogRelIs12Enabled() LogRelIsItEnabled(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP)
1311
1312/** @def LogRelIsFlowEnabled
1313 * Checks whether execution flow release logging is enabled.
1314 */
1315#define LogRelIsFlowEnabled() LogRelIsItEnabled(RTLOGGRPFLAGS_FLOW, LOG_GROUP)
1316
1317/** @def LogRelIsWarnEnabled
1318 * Checks whether warning level release logging is enabled.
1319 */
1320#define LogRelIsWarnEnabled() LogRelIsItEnabled(RTLOGGRPFLAGS_FLOW, LOG_GROUP)
1321/** @} */
1322
1323
1324/** @def LogRelIt
1325 * Write to specific logger if group enabled.
1326 */
1327/** @def LogRelItLikely
1328 * Write to specific logger if group enabled, assuming it likely it is enabled.
1329 */
1330/** @def LogRelMaxIt
1331 * Write to specific logger if group enabled and at less than a_cMax messages
1332 * have hit the log. Uses a static variable to count.
1333 */
1334#ifdef RTLOG_REL_ENABLED
1335# if defined(LOG_USE_C99)
1336# define _LogRelRemoveParentheseis(...) __VA_ARGS__
1337# define _LogRelIt(a_fFlags, a_iGroup, ...) \
1338 do \
1339 { \
1340 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1341 if (RT_LIKELY(!LogRelIt_pLogger)) \
1342 { /* likely */ } \
1343 else \
1344 RTLogLoggerEx(LogRelIt_pLogger, a_fFlags, a_iGroup, __VA_ARGS__); \
1345 _LogIt(a_fFlags, a_iGroup, __VA_ARGS__); \
1346 } while (0)
1347# define LogRelIt(a_fFlags, a_iGroup, fmtargs) \
1348 _LogRelIt(a_fFlags, a_iGroup, _LogRelRemoveParentheseis fmtargs)
1349# define _LogRelItLikely(a_fFlags, a_iGroup, ...) \
1350 do \
1351 { \
1352 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1353 if (LogRelIt_pLogger) \
1354 RTLogLoggerEx(LogRelIt_pLogger, a_fFlags, a_iGroup, __VA_ARGS__); \
1355 _LogIt(a_fFlags, a_iGroup, __VA_ARGS__); \
1356 } while (0)
1357# define LogRelItLikely(a_fFlags, a_iGroup, fmtargs) \
1358 _LogRelItLikely(a_fFlags, a_iGroup, _LogRelRemoveParentheseis fmtargs)
1359# define _LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, ...) \
1360 do \
1361 { \
1362 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1363 if (LogRelIt_pLogger) \
1364 { \
1365 static uint32_t s_LogRelMaxIt_cLogged = 0; \
1366 if (s_LogRelMaxIt_cLogged < (a_cMax)) \
1367 { \
1368 s_LogRelMaxIt_cLogged++; \
1369 RTLogLoggerEx(LogRelIt_pLogger, a_fFlags, a_iGroup, __VA_ARGS__); \
1370 } \
1371 } \
1372 _LogIt(a_fFlags, a_iGroup, __VA_ARGS__); \
1373 } while (0)
1374# define LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, fmtargs) \
1375 _LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, _LogRelRemoveParentheseis fmtargs)
1376# else
1377# define LogRelItLikely(a_fFlags, a_iGroup, fmtargs) \
1378 do \
1379 { \
1380 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1381 if (LogRelIt_pLogger) \
1382 { \
1383 LogRelIt_pLogger->pfnLogger fmtargs; \
1384 } \
1385 LogIt(a_fFlags, a_iGroup, fmtargs); \
1386 } while (0)
1387# define LogRelIt(a_fFlags, a_iGroup, fmtargs) \
1388 do \
1389 { \
1390 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1391 if (RT_LIKELY(!LogRelIt_pLogger)) \
1392 { /* likely */ } \
1393 else \
1394 { \
1395 LogRelIt_pLogger->pfnLogger fmtargs; \
1396 } \
1397 LogIt(a_fFlags, a_iGroup, fmtargs); \
1398 } while (0)
1399# define LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, fmtargs) \
1400 do \
1401 { \
1402 PRTLOGGER LogRelIt_pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(a_fFlags, a_iGroup)); \
1403 if (LogRelIt_pLogger) \
1404 { \
1405 static uint32_t s_LogRelMaxIt_cLogged = 0; \
1406 if (s_LogRelMaxIt_cLogged < (a_cMax)) \
1407 { \
1408 s_LogRelMaxIt_cLogged++; \
1409 LogRelIt_pLogger->pfnLogger fmtargs; \
1410 } \
1411 } \
1412 LogIt(a_fFlags, a_iGroup, fmtargs); \
1413 } while (0)
1414# endif
1415#else /* !RTLOG_REL_ENABLED */
1416# define LogRelIt(a_fFlags, a_iGroup, fmtargs) do { } while (0)
1417# define LogRelItLikely(a_fFlags, a_iGroup, fmtargs) do { } while (0)
1418# define LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, fmtargs) do { } while (0)
1419# if defined(LOG_USE_C99)
1420# define _LogRelRemoveParentheseis(...) __VA_ARGS__
1421# define _LogRelIt(a_fFlags, a_iGroup, ...) do { } while (0)
1422# define _LogRelItLikely(a_fFlags, a_iGroup, ...) do { } while (0)
1423# define _LogRelMaxIt(a_cMax, a_fFlags, a_iGroup, ...) do { } while (0)
1424# endif
1425#endif /* !RTLOG_REL_ENABLED */
1426
1427
1428/** @name Basic release logging macros
1429 * @{ */
1430/** @def LogRel
1431 * Level 1 release logging.
1432 */
1433#define LogRel(a) LogRelItLikely(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
1434
1435/** @def LogRel2
1436 * Level 2 release logging.
1437 */
1438#define LogRel2(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, a)
1439
1440/** @def LogRel3
1441 * Level 3 release logging.
1442 */
1443#define LogRel3(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, a)
1444
1445/** @def LogRel4
1446 * Level 4 release logging.
1447 */
1448#define LogRel4(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, a)
1449
1450/** @def LogRel5
1451 * Level 5 release logging.
1452 */
1453#define LogRel5(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, a)
1454
1455/** @def LogRel6
1456 * Level 6 release logging.
1457 */
1458#define LogRel6(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, a)
1459
1460/** @def LogRel7
1461 * Level 7 release logging.
1462 */
1463#define LogRel7(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP, a)
1464
1465/** @def LogRel8
1466 * Level 8 release logging.
1467 */
1468#define LogRel8(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP, a)
1469
1470/** @def LogRel9
1471 * Level 9 release logging.
1472 */
1473#define LogRel9(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP, a)
1474
1475/** @def LogRel10
1476 * Level 10 release logging.
1477 */
1478#define LogRel10(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP, a)
1479
1480/** @def LogRel11
1481 * Level 11 release logging.
1482 */
1483#define LogRel11(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP, a)
1484
1485/** @def LogRel12
1486 * Level 12 release logging.
1487 */
1488#define LogRel12(a) LogRelIt(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP, a)
1489
1490/** @def LogRelFlow
1491 * Logging of execution flow.
1492 */
1493#define LogRelFlow(a) LogRelIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP, a)
1494
1495/** @def LogRelWarn
1496 * Warning level release logging.
1497 */
1498#define LogRelWarn(a) LogRelIt(RTLOGGRPFLAGS_WARN, LOG_GROUP, a)
1499/** @} */
1500
1501
1502
1503/** @name Basic release logging macros with local max
1504 * @{ */
1505/** @def LogRelMax
1506 * Level 1 release logging with a max number of log entries.
1507 */
1508#define LogRelMax(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, a)
1509
1510/** @def LogRelMax2
1511 * Level 2 release logging with a max number of log entries.
1512 */
1513#define LogRelMax2(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP, a)
1514
1515/** @def LogRelMax3
1516 * Level 3 release logging with a max number of log entries.
1517 */
1518#define LogRelMax3(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP, a)
1519
1520/** @def LogRelMax4
1521 * Level 4 release logging with a max number of log entries.
1522 */
1523#define LogRelMax4(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP, a)
1524
1525/** @def LogRelMax5
1526 * Level 5 release logging with a max number of log entries.
1527 */
1528#define LogRelMax5(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP, a)
1529
1530/** @def LogRelMax6
1531 * Level 6 release logging with a max number of log entries.
1532 */
1533#define LogRelMax6(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP, a)
1534
1535/** @def LogRelMax7
1536 * Level 7 release logging with a max number of log entries.
1537 */
1538#define LogRelMax7(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_7, LOG_GROUP, a)
1539
1540/** @def LogRelMax8
1541 * Level 8 release logging with a max number of log entries.
1542 */
1543#define LogRelMax8(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_8, LOG_GROUP, a)
1544
1545/** @def LogRelMax9
1546 * Level 9 release logging with a max number of log entries.
1547 */
1548#define LogRelMax9(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_9, LOG_GROUP, a)
1549
1550/** @def LogRelMax10
1551 * Level 10 release logging with a max number of log entries.
1552 */
1553#define LogRelMax10(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_10, LOG_GROUP, a)
1554
1555/** @def LogRelMax11
1556 * Level 11 release logging with a max number of log entries.
1557 */
1558#define LogRelMax11(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_11, LOG_GROUP, a)
1559
1560/** @def LogRelMax12
1561 * Level 12 release logging with a max number of log entries.
1562 */
1563#define LogRelMax12(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP, a)
1564
1565/** @def LogRelFlow
1566 * Logging of execution flow with a max number of log entries.
1567 */
1568#define LogRelMaxFlow(a_cMax, a) LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_FLOW, LOG_GROUP, a)
1569/** @} */
1570
1571
1572/** @name Release logging macros prefixing the current function name.
1573 * @{ */
1574
1575/** @def LogRelFunc
1576 * Release logging. Prepends the given log message with the function name
1577 * followed by a semicolon and space.
1578 */
1579#ifdef LOG_USE_C99
1580# define LogRelFunc(a) \
1581 _LogRelItLikely(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", RT_GCC_EXTENSION __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1582#else
1583# define LogRelFunc(a) do { LogRel((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRel(a); } while (0)
1584#endif
1585
1586/** @def LogRelFlowFunc
1587 * Release logging. Macro to log the execution flow inside C/C++ functions.
1588 *
1589 * Prepends the given log message with the function name followed by
1590 * a semicolon and space.
1591 *
1592 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1593 */
1594#ifdef LOG_USE_C99
1595# define LogRelFlowFunc(a) _LogRelIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1596#else
1597# define LogRelFlowFunc(a) do { LogRelFlow((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRelFlow(a); } while (0)
1598#endif
1599
1600/** @def LogRelMaxFunc
1601 * Release logging. Prepends the given log message with the function name
1602 * followed by a semicolon and space.
1603 */
1604#ifdef LOG_USE_C99
1605# define LogRelMaxFunc(a_cMax, a) \
1606 _LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1607#else
1608# define LogRelMaxFunc(a_cMax, a) \
1609 do { LogRelMax(a_cMax, (LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRelMax(a_cMax, a); } while (0)
1610#endif
1611
1612/** @def LogRelMaxFlowFunc
1613 * Release logging. Macro to log the execution flow inside C/C++ functions.
1614 *
1615 * Prepends the given log message with the function name followed by
1616 * a semicolon and space.
1617 *
1618 * @param a_cMax Max number of times this should hit the log.
1619 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1620 */
1621#ifdef LOG_USE_C99
1622# define LogRelMaxFlowFunc(a_cMax, a) \
1623 _LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_FLOW, LOG_GROUP, LOG_FN_FMT ": %M", __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1624#else
1625# define LogRelMaxFlowFunc(a_cMax, a) \
1626 do { LogRelMaxFlow(a_cMax, (LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRelFlow(a_cMax, a); } while (0)
1627#endif
1628
1629/** @} */
1630
1631
1632/** @name Release Logging macros prefixing the this pointer value and method name.
1633 * @{ */
1634
1635/** @def LogRelThisFunc
1636 * The same as LogRelFunc but for class functions (methods): the resulting log
1637 * line is additionally prepended with a hex value of |this| pointer.
1638 */
1639#ifdef LOG_USE_C99
1640# define LogRelThisFunc(a) \
1641 _LogRelItLikely(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1642#else
1643# define LogRelThisFunc(a) \
1644 do { LogRel(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogRel(a); } while (0)
1645#endif
1646
1647/** @def LogRelMaxThisFunc
1648 * The same as LogRelFunc but for class functions (methods): the resulting log
1649 * line is additionally prepended with a hex value of |this| pointer.
1650 * @param a_cMax Max number of times this should hit the log.
1651 * @param a Log message in format <tt>("string\n" [, args])</tt>.
1652 */
1653#ifdef LOG_USE_C99
1654# define LogRelMaxThisFunc(a_cMax, a) \
1655 _LogRelMaxIt(a_cMax, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP, "{%p} " LOG_FN_FMT ": %M", this, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
1656#else
1657# define LogRelMaxThisFunc(a_cMax, a) \
1658 do { LogRelMax(a_cMax, ("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogRelMax(a_cMax, a); } while (0)
1659#endif
1660
1661/** @} */
1662
1663
1664#ifndef IN_RC
1665/**
1666 * Sets the default release logger instance.
1667 *
1668 * @returns The old default instance.
1669 * @param pLogger The new default release logger instance.
1670 */
1671RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger);
1672#endif /* !IN_RC */
1673
1674/**
1675 * Gets the default release logger instance.
1676 *
1677 * @returns Pointer to default release logger instance if availble, otherwise NULL.
1678 */
1679RTDECL(PRTLOGGER) RTLogRelGetDefaultInstance(void);
1680
1681/**
1682 * Gets the default release logger instance.
1683 *
1684 * @returns Pointer to default release logger instance if availble, otherwise NULL.
1685 * @param fFlagsAndGroup The flags in the lower 16 bits, the group number in
1686 * the high 16 bits.
1687 */
1688RTDECL(PRTLOGGER) RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup);
1689
1690/**
1691 * Write to a logger instance, defaulting to the release one.
1692 *
1693 * This function will check whether the instance, group and flags makes up a
1694 * logging kind which is currently enabled before writing anything to the log.
1695 *
1696 * @param pLogger Pointer to logger instance.
1697 * @param fFlags The logging flags.
1698 * @param iGroup The group.
1699 * The value ~0U is reserved for compatibility with RTLogLogger[V] and is
1700 * only for internal usage!
1701 * @param pszFormat Format string.
1702 * @param ... Format arguments.
1703 * @remark This is a worker function for LogRelIt.
1704 */
1705RTDECL(void) RTLogRelLogger(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
1706
1707/**
1708 * Write to a logger instance, defaulting to the release one.
1709 *
1710 * This function will check whether the instance, group and flags makes up a
1711 * logging kind which is currently enabled before writing anything to the log.
1712 *
1713 * @param pLogger Pointer to logger instance. If NULL the default release instance is attempted.
1714 * @param fFlags The logging flags.
1715 * @param iGroup The group.
1716 * The value ~0U is reserved for compatibility with RTLogLogger[V] and is
1717 * only for internal usage!
1718 * @param pszFormat Format string.
1719 * @param args Format arguments.
1720 */
1721RTDECL(void) RTLogRelLoggerV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
1722
1723/**
1724 * printf like function for writing to the default release log.
1725 *
1726 * @param pszFormat Printf like format string.
1727 * @param ... Optional arguments as specified in pszFormat.
1728 *
1729 * @remark The API doesn't support formatting of floating point numbers at the moment.
1730 */
1731RTDECL(void) RTLogRelPrintf(const char *pszFormat, ...);
1732
1733/**
1734 * vprintf like function for writing to the default release log.
1735 *
1736 * @param pszFormat Printf like format string.
1737 * @param args Optional arguments as specified in pszFormat.
1738 *
1739 * @remark The API doesn't support formatting of floating point numbers at the moment.
1740 */
1741RTDECL(void) RTLogRelPrintfV(const char *pszFormat, va_list args);
1742
1743/**
1744 * Changes the buffering setting of the default release logger.
1745 *
1746 * This can be used for optimizing longish logging sequences.
1747 *
1748 * @returns The old state.
1749 * @param fBuffered The new state.
1750 */
1751RTDECL(bool) RTLogRelSetBuffering(bool fBuffered);
1752
1753/** @} */
1754
1755
1756
1757/** @name COM port logging
1758 * {
1759 */
1760
1761#ifdef DOXYGEN_RUNNING
1762# define LOG_TO_COM
1763# define LOG_NO_COM
1764#endif
1765
1766/** @def LOG_TO_COM
1767 * Redirects the normal logging macros to the serial versions.
1768 */
1769
1770/** @def LOG_NO_COM
1771 * Disables all LogCom* macros.
1772 */
1773
1774/** @def LogCom
1775 * Generic logging to serial port.
1776 */
1777#if defined(LOG_ENABLED) && !defined(LOG_NO_COM)
1778# define LogCom(a) RTLogComPrintf a
1779#else
1780# define LogCom(a) do { } while (0)
1781#endif
1782
1783/** @def LogComFlow
1784 * Logging to serial port of execution flow.
1785 */
1786#if defined(LOG_ENABLED) && defined(LOG_ENABLE_FLOW) && !defined(LOG_NO_COM)
1787# define LogComFlow(a) RTLogComPrintf a
1788#else
1789# define LogComFlow(a) do { } while (0)
1790#endif
1791
1792#ifdef LOG_TO_COM
1793# undef Log
1794# define Log(a) LogCom(a)
1795# undef LogFlow
1796# define LogFlow(a) LogComFlow(a)
1797#endif
1798
1799/** @} */
1800
1801
1802/** @name Backdoor Logging
1803 * @{
1804 */
1805
1806#ifdef DOXYGEN_RUNNING
1807# define LOG_TO_BACKDOOR
1808# define LOG_NO_BACKDOOR
1809#endif
1810
1811/** @def LOG_TO_BACKDOOR
1812 * Redirects the normal logging macros to the backdoor versions.
1813 */
1814
1815/** @def LOG_NO_BACKDOOR
1816 * Disables all LogBackdoor* macros.
1817 */
1818
1819/** @def LogBackdoor
1820 * Generic logging to the VBox backdoor via port I/O.
1821 */
1822#if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
1823# define LogBackdoor(a) RTLogBackdoorPrintf a
1824#else
1825# define LogBackdoor(a) do { } while (0)
1826#endif
1827
1828/** @def LogBackdoorFlow
1829 * Logging of execution flow messages to the backdoor I/O port.
1830 */
1831#if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
1832# define LogBackdoorFlow(a) RTLogBackdoorPrintf a
1833#else
1834# define LogBackdoorFlow(a) do { } while (0)
1835#endif
1836
1837/** @def LogRelBackdoor
1838 * Release logging to the VBox backdoor via port I/O.
1839 */
1840#if !defined(LOG_NO_BACKDOOR)
1841# define LogRelBackdoor(a) RTLogBackdoorPrintf a
1842#else
1843# define LogRelBackdoor(a) do { } while (0)
1844#endif
1845
1846#ifdef LOG_TO_BACKDOOR
1847# undef Log
1848# define Log(a) LogBackdoor(a)
1849# undef LogFlow
1850# define LogFlow(a) LogBackdoorFlow(a)
1851# undef LogRel
1852# define LogRel(a) LogRelBackdoor(a)
1853# if defined(LOG_USE_C99)
1854# undef _LogIt
1855# define _LogIt(a_fFlags, a_iGroup, ...) LogBackdoor((__VA_ARGS__))
1856# endif
1857#endif
1858
1859/** @} */
1860
1861
1862
1863/**
1864 * Gets the default logger instance, creating it if necessary.
1865 *
1866 * @returns Pointer to default logger instance if availble, otherwise NULL.
1867 */
1868RTDECL(PRTLOGGER) RTLogDefaultInstance(void);
1869
1870/**
1871 * Gets the logger instance if enabled, creating it if necessary.
1872 *
1873 * @returns Pointer to default logger instance, if group has the specified
1874 * flags enabled. Otherwise NULL is returned.
1875 * @param fFlagsAndGroup The flags in the lower 16 bits, the group number in
1876 * the high 16 bits.
1877 */
1878RTDECL(PRTLOGGER) RTLogDefaultInstanceEx(uint32_t fFlagsAndGroup);
1879
1880/**
1881 * Gets the default logger instance.
1882 *
1883 * @returns Pointer to default logger instance if availble, otherwise NULL.
1884 */
1885RTDECL(PRTLOGGER) RTLogGetDefaultInstance(void);
1886
1887/**
1888 * Gets the default logger instance if enabled.
1889 *
1890 * @returns Pointer to default logger instance, if group has the specified
1891 * flags enabled. Otherwise NULL is returned.
1892 * @param fFlagsAndGroup The flags in the lower 16 bits, the group number in
1893 * the high 16 bits.
1894 */
1895RTDECL(PRTLOGGER) RTLogGetDefaultInstanceEx(uint32_t fFlagsAndGroup);
1896
1897#ifndef IN_RC
1898/**
1899 * Sets the default logger instance.
1900 *
1901 * @returns The old default instance.
1902 * @param pLogger The new default logger instance.
1903 */
1904RTDECL(PRTLOGGER) RTLogSetDefaultInstance(PRTLOGGER pLogger);
1905#endif /* !IN_RC */
1906
1907#ifdef IN_RING0
1908/**
1909 * Changes the default logger instance for the current thread.
1910 *
1911 * @returns IPRT status code.
1912 * @param pLogger The logger instance. Pass NULL for deregistration.
1913 * @param uKey Associated key for cleanup purposes. If pLogger is NULL,
1914 * all instances with this key will be deregistered. So in
1915 * order to only deregister the instance associated with the
1916 * current thread use 0.
1917 */
1918RTDECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
1919#endif /* IN_RING0 */
1920
1921
1922#ifndef IN_RC
1923/**
1924 * Creates the default logger instance for a iprt users.
1925 *
1926 * Any user of the logging features will need to implement
1927 * this or use the generic dummy.
1928 *
1929 * @returns Pointer to the logger instance.
1930 */
1931RTDECL(PRTLOGGER) RTLogDefaultInit(void);
1932
1933/**
1934 * Create a logger instance.
1935 *
1936 * @returns iprt status code.
1937 *
1938 * @param ppLogger Where to store the logger instance.
1939 * @param fFlags Logger instance flags, a combination of the
1940 * RTLOGFLAGS_* values.
1941 * @param pszGroupSettings The initial group settings.
1942 * @param pszEnvVarBase Base name for the environment variables for
1943 * this instance.
1944 * @param cGroups Number of groups in the array.
1945 * @param papszGroups Pointer to array of groups. This must stick
1946 * around for the life of the logger instance.
1947 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed
1948 * if pszFilenameFmt specified.
1949 * @param pszFilenameFmt Log filename format string. Standard
1950 * RTStrFormat().
1951 * @param ... Format arguments.
1952 */
1953RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
1954 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1955 uint32_t fDestFlags, const char *pszFilenameFmt, ...);
1956
1957/**
1958 * Create a logger instance.
1959 *
1960 * @returns iprt status code.
1961 *
1962 * @param ppLogger Where to store the logger instance.
1963 * @param fFlags Logger instance flags, a combination of the
1964 * RTLOGFLAGS_* values.
1965 * @param pszGroupSettings The initial group settings.
1966 * @param pszEnvVarBase Base name for the environment variables for
1967 * this instance.
1968 * @param cGroups Number of groups in the array.
1969 * @param papszGroups Pointer to array of groups. This must stick
1970 * around for the life of the logger instance.
1971 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed
1972 * if pszFilenameFmt specified.
1973 * @param pfnPhase Callback function for starting logging and for
1974 * ending or starting a new file for log history
1975 * rotation. NULL is OK.
1976 * @param cHistory Number of old log files to keep when performing
1977 * log history rotation. 0 means no history.
1978 * @param cbHistoryFileMax Maximum size of log file when performing
1979 * history rotation. 0 means no size limit.
1980 * @param cSecsHistoryTimeSlot Maximum time interval per log file when
1981 * performing history rotation, in seconds.
1982 * 0 means time limit.
1983 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
1984 * @param cchErrorMsg The size of the error message buffer.
1985 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1986 * @param ... Format arguments.
1987 */
1988RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
1989 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1990 uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory,
1991 uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot,
1992 char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...);
1993
1994/**
1995 * Create a logger instance.
1996 *
1997 * @returns iprt status code.
1998 *
1999 * @param ppLogger Where to store the logger instance.
2000 * @param fFlags Logger instance flags, a combination of the
2001 * RTLOGFLAGS_* values.
2002 * @param pszGroupSettings The initial group settings.
2003 * @param pszEnvVarBase Base name for the environment variables for
2004 * this instance.
2005 * @param cGroups Number of groups in the array.
2006 * @param papszGroups Pointer to array of groups. This must stick
2007 * around for the life of the logger instance.
2008 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed
2009 * if pszFilenameFmt specified.
2010 * @param pfnPhase Callback function for starting logging and for
2011 * ending or starting a new file for log history
2012 * rotation.
2013 * @param cHistory Number of old log files to keep when performing
2014 * log history rotation. 0 means no history.
2015 * @param cbHistoryFileMax Maximum size of log file when performing
2016 * history rotation. 0 means no size limit.
2017 * @param cSecsHistoryTimeSlot Maximum time interval per log file when
2018 * performing history rotation, in seconds.
2019 * 0 means no time limit.
2020 * @param pszErrorMsg A buffer which is filled with an error message
2021 * if something fails. May be NULL.
2022 * @param cchErrorMsg The size of the error message buffer.
2023 * @param pszFilenameFmt Log filename format string. Standard
2024 * RTStrFormat().
2025 * @param args Format arguments.
2026 */
2027RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings,
2028 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
2029 uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory,
2030 uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot,
2031 char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args);
2032
2033/**
2034 * Create a logger instance for singled threaded ring-0 usage.
2035 *
2036 * @returns iprt status code.
2037 *
2038 * @param pLogger Where to create the logger instance.
2039 * @param cbLogger The amount of memory available for the logger instance.
2040 * @param pLoggerR0Ptr The ring-0 address corresponding to @a pLogger.
2041 * @param pfnLoggerR0Ptr Pointer to logger wrapper function.
2042 * @param pfnFlushR0Ptr Pointer to flush function.
2043 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
2044 * @param fDestFlags The destination flags.
2045 */
2046RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger,
2047 RTR0PTR pLoggerR0Ptr, RTR0PTR pfnLoggerR0Ptr, RTR0PTR pfnFlushR0Ptr,
2048 uint32_t fFlags, uint32_t fDestFlags);
2049
2050/**
2051 * Calculates the minimum size of a ring-0 logger instance.
2052 *
2053 * @returns The minimum size.
2054 * @param cGroups The number of groups.
2055 * @param fFlags Relevant flags.
2056 */
2057RTDECL(size_t) RTLogCalcSizeForR0(uint32_t cGroups, uint32_t fFlags);
2058
2059/**
2060 * Destroys a logger instance.
2061 *
2062 * The instance is flushed and all output destinations closed (where applicable).
2063 *
2064 * @returns iprt status code.
2065 * @param pLogger The logger instance which close destroyed. NULL is fine.
2066 */
2067RTDECL(int) RTLogDestroy(PRTLOGGER pLogger);
2068
2069/**
2070 * Create a logger instance clone for RC usage.
2071 *
2072 * @returns iprt status code.
2073 *
2074 * @param pLogger The logger instance to be cloned.
2075 * @param pLoggerRC Where to create the RC logger instance.
2076 * @param cbLoggerRC Amount of memory allocated to for the RC logger
2077 * instance clone.
2078 * @param pfnLoggerRCPtr Pointer to logger wrapper function for this
2079 * instance (RC Ptr).
2080 * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).
2081 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
2082 */
2083RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,
2084 RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, uint32_t fFlags);
2085
2086/**
2087 * Flushes a RC logger instance to a R3 logger.
2088 *
2089 * @returns iprt status code.
2090 * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL
2091 * the default logger is used.
2092 * @param pLoggerRC The RC logger instance to flush.
2093 */
2094RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC);
2095
2096/**
2097 * Flushes the buffer in one logger instance onto another logger.
2098 *
2099 * @returns iprt status code.
2100 *
2101 * @param pSrcLogger The logger instance to flush.
2102 * @param pDstLogger The logger instance to flush onto.
2103 * If NULL the default logger will be used.
2104 */
2105RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger);
2106
2107/**
2108 * Flushes a R0 logger instance to a R3 logger.
2109 *
2110 * @returns iprt status code.
2111 * @param pLogger The R3 logger instance to flush pLoggerR0 to. If NULL
2112 * the default logger is used.
2113 * @param pLoggerR0 The R0 logger instance to flush.
2114 */
2115RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0);
2116
2117/**
2118 * Sets the custom prefix callback.
2119 *
2120 * @returns IPRT status code.
2121 * @param pLogger The logger instance.
2122 * @param pfnCallback The callback.
2123 * @param pvUser The user argument for the callback.
2124 * */
2125RTDECL(int) RTLogSetCustomPrefixCallback(PRTLOGGER pLogger, PFNRTLOGPREFIX pfnCallback, void *pvUser);
2126
2127/**
2128 * Same as RTLogSetCustomPrefixCallback for loggers created by
2129 * RTLogCreateForR0.
2130 *
2131 * @returns IPRT status code.
2132 * @param pLogger The logger instance.
2133 * @param pLoggerR0Ptr The ring-0 address corresponding to @a pLogger.
2134 * @param pfnCallbackR0Ptr The callback.
2135 * @param pvUserR0Ptr The user argument for the callback.
2136 * */
2137RTDECL(int) RTLogSetCustomPrefixCallbackForR0(PRTLOGGER pLogger, RTR0PTR pLoggerR0Ptr,
2138 RTR0PTR pfnCallbackR0Ptr, RTR0PTR pvUserR0Ptr);
2139
2140/**
2141 * Copies the group settings and flags from logger instance to another.
2142 *
2143 * @returns IPRT status code.
2144 * @param pDstLogger The destination logger instance.
2145 * @param pDstLoggerR0Ptr The ring-0 address corresponding to @a pDstLogger.
2146 * @param pSrcLogger The source logger instance. If NULL the default one is used.
2147 * @param fFlagsOr OR mask for the flags.
2148 * @param fFlagsAnd AND mask for the flags.
2149 */
2150RTDECL(int) RTLogCopyGroupsAndFlagsForR0(PRTLOGGER pDstLogger, RTR0PTR pDstLoggerR0Ptr,
2151 PCRTLOGGER pSrcLogger, uint32_t fFlagsOr, uint32_t fFlagsAnd);
2152
2153/**
2154 * Get the current log group settings as a string.
2155 *
2156 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
2157 * @param pLogger Logger instance (NULL for default logger).
2158 * @param pszBuf The output buffer.
2159 * @param cchBuf The size of the output buffer. Must be greater
2160 * than zero.
2161 */
2162RTDECL(int) RTLogGetGroupSettings(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
2163
2164/**
2165 * Updates the group settings for the logger instance using the specified
2166 * specification string.
2167 *
2168 * @returns iprt status code.
2169 * Failures can safely be ignored.
2170 * @param pLogger Logger instance (NULL for default logger).
2171 * @param pszValue Value to parse.
2172 */
2173RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszValue);
2174#endif /* !IN_RC */
2175
2176/**
2177 * Updates the flags for the logger instance using the specified
2178 * specification string.
2179 *
2180 * @returns iprt status code.
2181 * Failures can safely be ignored.
2182 * @param pLogger Logger instance (NULL for default logger).
2183 * @param pszValue Value to parse.
2184 */
2185RTDECL(int) RTLogFlags(PRTLOGGER pLogger, const char *pszValue);
2186
2187/**
2188 * Changes the buffering setting of the specified logger.
2189 *
2190 * This can be used for optimizing longish logging sequences.
2191 *
2192 * @returns The old state.
2193 * @param pLogger The logger instance (NULL is an alias for the
2194 * default logger).
2195 * @param fBuffered The new state.
2196 */
2197RTDECL(bool) RTLogSetBuffering(PRTLOGGER pLogger, bool fBuffered);
2198
2199/**
2200 * Sets the max number of entries per group.
2201 *
2202 * @returns Old restriction.
2203 *
2204 * @param pLogger The logger instance (NULL is an alias for the
2205 * default logger).
2206 * @param cMaxEntriesPerGroup The max number of entries per group.
2207 *
2208 * @remarks Lowering the limit of an active logger may quietly mute groups.
2209 * Raising it may reactive already muted groups.
2210 */
2211RTDECL(uint32_t) RTLogSetGroupLimit(PRTLOGGER pLogger, uint32_t cMaxEntriesPerGroup);
2212
2213#ifndef IN_RC
2214/**
2215 * Get the current log flags as a string.
2216 *
2217 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
2218 * @param pLogger Logger instance (NULL for default logger).
2219 * @param pszBuf The output buffer.
2220 * @param cchBuf The size of the output buffer. Must be greater
2221 * than zero.
2222 */
2223RTDECL(int) RTLogGetFlags(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
2224
2225/**
2226 * Updates the logger destination using the specified string.
2227 *
2228 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
2229 * @param pLogger Logger instance (NULL for default logger).
2230 * @param pszValue The value to parse.
2231 */
2232RTDECL(int) RTLogDestinations(PRTLOGGER pLogger, char const *pszValue);
2233
2234/**
2235 * Get the current log destinations as a string.
2236 *
2237 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
2238 * @param pLogger Logger instance (NULL for default logger).
2239 * @param pszBuf The output buffer.
2240 * @param cchBuf The size of the output buffer. Must be greater
2241 * than 0.
2242 */
2243RTDECL(int) RTLogGetDestinations(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
2244#endif /* !IN_RC */
2245
2246/**
2247 * Flushes the specified logger.
2248 *
2249 * @param pLogger The logger instance to flush.
2250 * If NULL the default instance is used. The default instance
2251 * will not be initialized by this call.
2252 */
2253RTDECL(void) RTLogFlush(PRTLOGGER pLogger);
2254
2255/**
2256 * Write to a logger instance.
2257 *
2258 * @param pLogger Pointer to logger instance.
2259 * @param pvCallerRet Ignored.
2260 * @param pszFormat Format string.
2261 * @param ... Format arguments.
2262 */
2263RTDECL(void) RTLogLogger(PRTLOGGER pLogger, void *pvCallerRet, const char *pszFormat, ...);
2264
2265/**
2266 * Write to a logger instance.
2267 *
2268 * @param pLogger Pointer to logger instance.
2269 * @param pszFormat Format string.
2270 * @param args Format arguments.
2271 */
2272RTDECL(void) RTLogLoggerV(PRTLOGGER pLogger, const char *pszFormat, va_list args);
2273
2274/**
2275 * Write to a logger instance.
2276 *
2277 * This function will check whether the instance, group and flags makes up a
2278 * logging kind which is currently enabled before writing anything to the log.
2279 *
2280 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
2281 * @param fFlags The logging flags.
2282 * @param iGroup The group.
2283 * The value ~0U is reserved for compatibility with RTLogLogger[V] and is
2284 * only for internal usage!
2285 * @param pszFormat Format string.
2286 * @param ... Format arguments.
2287 * @remark This is a worker function of LogIt.
2288 */
2289RTDECL(void) RTLogLoggerEx(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
2290
2291/**
2292 * Write to a logger instance.
2293 *
2294 * This function will check whether the instance, group and flags makes up a
2295 * logging kind which is currently enabled before writing anything to the log.
2296 *
2297 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
2298 * @param fFlags The logging flags.
2299 * @param iGroup The group.
2300 * The value ~0U is reserved for compatibility with RTLogLogger[V] and is
2301 * only for internal usage!
2302 * @param pszFormat Format string.
2303 * @param args Format arguments.
2304 */
2305RTDECL(void) RTLogLoggerExV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
2306
2307/**
2308 * printf like function for writing to the default log.
2309 *
2310 * @param pszFormat Printf like format string.
2311 * @param ... Optional arguments as specified in pszFormat.
2312 *
2313 * @remark The API doesn't support formatting of floating point numbers at the moment.
2314 */
2315RTDECL(void) RTLogPrintf(const char *pszFormat, ...);
2316
2317/**
2318 * vprintf like function for writing to the default log.
2319 *
2320 * @param pszFormat Printf like format string.
2321 * @param args Optional arguments as specified in pszFormat.
2322 *
2323 * @remark The API doesn't support formatting of floating point numbers at the moment.
2324 */
2325RTDECL(void) RTLogPrintfV(const char *pszFormat, va_list args);
2326
2327/**
2328 * Dumper vprintf-like function outputting to a logger.
2329 *
2330 * @param pvUser Pointer to the logger instance to use, NULL for
2331 * default instance.
2332 * @param pszFormat Format string.
2333 * @param va Format arguments.
2334 */
2335RTDECL(void) RTLogDumpPrintfV(void *pvUser, const char *pszFormat, va_list va);
2336
2337
2338#ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/string.h */
2339#define DECLARED_FNRTSTROUTPUT
2340/**
2341 * Output callback.
2342 *
2343 * @returns number of bytes written.
2344 * @param pvArg User argument.
2345 * @param pachChars Pointer to an array of utf-8 characters.
2346 * @param cbChars Number of bytes in the character array pointed to by pachChars.
2347 */
2348typedef DECLCALLBACK(size_t) FNRTSTROUTPUT(void *pvArg, const char *pachChars, size_t cbChars);
2349/** Pointer to callback function. */
2350typedef FNRTSTROUTPUT *PFNRTSTROUTPUT;
2351#endif
2352
2353/**
2354 * Partial vsprintf worker implementation.
2355 *
2356 * @returns number of bytes formatted.
2357 * @param pfnOutput Output worker.
2358 * Called in two ways. Normally with a string an it's length.
2359 * For termination, it's called with NULL for string, 0 for length.
2360 * @param pvArg Argument to output worker.
2361 * @param pszFormat Format string.
2362 * @param args Argument list.
2363 */
2364RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args);
2365
2366/**
2367 * Write log buffer to COM port.
2368 *
2369 * @param pach Pointer to the buffer to write.
2370 * @param cb Number of bytes to write.
2371 */
2372RTDECL(void) RTLogWriteCom(const char *pach, size_t cb);
2373
2374/**
2375 * Prints a formatted string to the serial port used for logging.
2376 *
2377 * @returns Number of bytes written.
2378 * @param pszFormat Format string.
2379 * @param ... Optional arguments specified in the format string.
2380 */
2381RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...);
2382
2383/**
2384 * Prints a formatted string to the serial port used for logging.
2385 *
2386 * @returns Number of bytes written.
2387 * @param pszFormat Format string.
2388 * @param args Optional arguments specified in the format string.
2389 */
2390RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args);
2391
2392
2393#if 0 /* not implemented yet */
2394
2395/** Indicates that the semaphores shall be used to notify the other
2396 * part about buffer changes. */
2397#define LOGHOOKBUFFER_FLAGS_SEMAPHORED 1
2398
2399/**
2400 * Log Hook Buffer.
2401 * Use to communicate between the logger and a log consumer.
2402 */
2403typedef struct RTLOGHOOKBUFFER
2404{
2405 /** Write pointer. */
2406 volatile void *pvWrite;
2407 /** Read pointer. */
2408 volatile void *pvRead;
2409 /** Buffer start. */
2410 void *pvStart;
2411 /** Buffer end (exclusive). */
2412 void *pvEnd;
2413 /** Signaling semaphore used by the writer to wait on a full buffer.
2414 * Only used when indicated in flags. */
2415 void *pvSemWriter;
2416 /** Signaling semaphore used by the read to wait on an empty buffer.
2417 * Only used when indicated in flags. */
2418 void *pvSemReader;
2419 /** Buffer flags. Current reserved and set to zero. */
2420 volatile unsigned fFlags;
2421} RTLOGHOOKBUFFER;
2422/** Pointer to a log hook buffer. */
2423typedef RTLOGHOOKBUFFER *PRTLOGHOOKBUFFER;
2424
2425
2426/**
2427 * Register a logging hook.
2428 *
2429 * This type of logging hooks are expecting different threads acting
2430 * producer and consumer. They share a circular buffer which have two
2431 * pointers one for each end. When the buffer is full there are two
2432 * alternatives (indicated by a buffer flag), either wait for the
2433 * consumer to get it's job done, or to write a generic message saying
2434 * buffer overflow.
2435 *
2436 * Since the waiting would need a signal semaphore, we'll skip that for now.
2437 *
2438 * @returns iprt status code.
2439 * @param pBuffer Pointer to a logger hook buffer.
2440 */
2441RTDECL(int) RTLogRegisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
2442
2443/**
2444 * Deregister a logging hook registered with RTLogRegisterHook().
2445 *
2446 * @returns iprt status code.
2447 * @param pBuffer Pointer to a logger hook buffer.
2448 */
2449RTDECL(int) RTLogDeregisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
2450
2451#endif /* not implemented yet */
2452
2453
2454
2455/**
2456 * Write log buffer to a debugger (RTLOGDEST_DEBUGGER).
2457 *
2458 * @param pach What to write.
2459 * @param cb How much to write.
2460 * @remark When linking statically, this function can be replaced by defining your own.
2461 */
2462RTDECL(void) RTLogWriteDebugger(const char *pach, size_t cb);
2463
2464/**
2465 * Write log buffer to a user defined output stream (RTLOGDEST_USER).
2466 *
2467 * @param pach What to write.
2468 * @param cb How much to write.
2469 * @remark When linking statically, this function can be replaced by defining your own.
2470 */
2471RTDECL(void) RTLogWriteUser(const char *pach, size_t cb);
2472
2473/**
2474 * Write log buffer to stdout (RTLOGDEST_STDOUT).
2475 *
2476 * @param pach What to write.
2477 * @param cb How much to write.
2478 * @remark When linking statically, this function can be replaced by defining your own.
2479 */
2480RTDECL(void) RTLogWriteStdOut(const char *pach, size_t cb);
2481
2482/**
2483 * Write log buffer to stdout (RTLOGDEST_STDERR).
2484 *
2485 * @param pach What to write.
2486 * @param cb How much to write.
2487 * @remark When linking statically, this function can be replaced by defining your own.
2488 */
2489RTDECL(void) RTLogWriteStdErr(const char *pach, size_t cb);
2490
2491#ifdef VBOX
2492
2493/**
2494 * Prints a formatted string to the backdoor port.
2495 *
2496 * @returns Number of bytes written.
2497 * @param pszFormat Format string.
2498 * @param ... Optional arguments specified in the format string.
2499 */
2500RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...);
2501
2502/**
2503 * Prints a formatted string to the backdoor port.
2504 *
2505 * @returns Number of bytes written.
2506 * @param pszFormat Format string.
2507 * @param args Optional arguments specified in the format string.
2508 */
2509RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args);
2510
2511#endif /* VBOX */
2512
2513RT_C_DECLS_END
2514
2515/** @} */
2516
2517#endif
2518
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