VirtualBox

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

Last change on this file since 70286 was 69752, checked in by vboxsync, 7 years ago

RTLogCreateEx[V] format annotations; fixed unsafe use in VBoxService.

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