VirtualBox

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

Last change on this file since 68113 was 66274, checked in by vboxsync, 8 years ago

VBox/Main: ​bugref:3300: VBoxSVC from terminal server session is not 'visible' - added VBoxSDS implementation

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