VirtualBox

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

Last change on this file since 100672 was 100672, checked in by vboxsync, 10 months ago

VMM/IEM: Some VxD syscall logging. bugref:10369

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

© 2023 Oracle
ContactPrivacy policyTerms of Use