VirtualBox

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

Last change on this file since 55980 was 55980, checked in by vboxsync, 10 years ago

iprt/log.h,++: Added extended logger instance getters that also checks whether the given logger and group-flags are enabled, making the LogRel* checks more efficient in avoid uncessary RTLogLoggerEx parameter building and calls. Ditto for debug logging. The LOG_INSTANCE and LOG_REL_INSTANCE tricks are gone for now.

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

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