VirtualBox

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

Last change on this file since 57682 was 57584, checked in by vboxsync, 9 years ago

IPRT: Implemented reading lib/Security/cacerts from JRE.

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