VirtualBox

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

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

include,tools/env.sh: applying sparc patches.

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