VirtualBox

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

Last change on this file since 59081 was 59081, checked in by vboxsync, 9 years ago

iprt/log.h: pedantic warnings for 32-bit gcc

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