VirtualBox

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

Last change on this file since 94480 was 93501, checked in by vboxsync, 3 years ago

IPRT/log: Define LOG_USE_C99 everywhere but on OS/2 and stop allocating executable memory when we don't need it.

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