VirtualBox

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

最後變更 在這個檔案從90838是 90829,由 vboxsync 提交於 4 年 前

IPRT,VMM,SUPDrv,++: Reworked the IPRT logger structure and how the VMM ring-0 uses it. bugref:10086

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette