VirtualBox

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

Last change on this file since 21699 was 21699, checked in by vboxsync, 16 years ago

iprt/log.h: Fixed the LogRel*Func macros.

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

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