VirtualBox

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

Last change on this file since 85202 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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

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