VirtualBox

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

Last change on this file since 69692 was 69105, checked in by vboxsync, 7 years ago

include/iprt/: (C) year

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