VirtualBox

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

Last change on this file since 28718 was 28695, checked in by vboxsync, 15 years ago

iprt/log: Added a write-through flag and a flush flag for file destination. Use RTFILE_O_APPEND (cleanup).

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