VirtualBox

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

Last change on this file since 81025 was 79949, checked in by vboxsync, 5 years ago

Runtime: bugref:8231 Starting on defining and implementing a new RTIoQueue API to replace RTFileAio mid term.

The RTIoQueue API is meant to be more efficient as it doesn't require allocation
of request structures and is only meant as a thin layer around host dependent APIs.
It will support mutiple providers for different handle types and the best suited provider
supported on a particular host can be selected. This allows multiple implementations
to coexist for the same host in an easy manner.
The providers currently being implemented are (in various stages of the implementation):

  • ioqueue-stdfile-provider.cpp:

A fallback provider if nothing else is available using the synchronous RTFile* APIs
emulating asynchronous behavior by using a dedicated worker thread.

  • ioqueue-aiofile-provider.cpp:

Uses the current RTFileAio* API, will get replaced by dedicated provider implementations for
each host later on.

  • ioqueue-iouringfile-provider.cpp:

Uses the recently added io_uring interface for Linux kernels 5.1 and newer. The new interface
is a great improvement over the old aio interface which is cumbersome to use and has various
restrictions. If not available on a host the code can fall back to one of the other providers.

The I/O queue interface is also meant to be suitable for sockets which can be implemented later.

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

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