VirtualBox

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

Last change on this file since 77807 was 77558, checked in by vboxsync, 6 years ago

IPRT: Moved the RTLogSetGroupLimit() functionality into the RTLogCreateEx() call, adding an env var for overriding it (suffix '_MAX_PER_GROUP', e.g. 'export VBOX_RELEASE_LOG_MAX_PER_GROUP=0' for no limit). [fix]

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

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use