VirtualBox

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

Last change on this file since 39667 was 38573, checked in by vboxsync, 13 years ago

iprt: Read dwarf line numbers.

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