VirtualBox

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

Last change on this file since 99805 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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

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