VirtualBox

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

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

IPRT: Added custom prefix callback to the logger.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.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[16384];
223 /** Current scratch buffer position. */
224 RTUINT offScratch;
225 /** This is set if a prefix is pending. */
226 RTUINT 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 RTUINT fFlags;
238 /** Number of groups in the afGroups member. */
239 RTUINT 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 RTUINT 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[16384];
260 /** Current scratch buffer position. */
261 RTUINT offScratch;
262 /** This is set if a prefix is pending. */
263 RTUINT 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 /** Mutex. */
277 RTSEMFASTMUTEX MutexSem;
278 /** Magic number. */
279 uint32_t u32Magic;
280 /** Logger instance flags - RTLOGFLAGS. */
281 RTUINT fFlags;
282 /** Destination flags - RTLOGDEST. */
283 RTUINT fDestFlags;
284 /** Handle to log file (if open). */
285 RTFILE File;
286 /** Pointer to filename.
287 * (The memory is allocated in the smae 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 RTUINT cMaxGroups;
295 /** Number of groups in the afGroups and papszGroups members. */
296 RTUINT 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 RTUINT 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 = 0x7cff8000
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#define LogRelFunc(a) \
930 do { LogRel((LOG_FN_FMT ": ", __PRETTY_FUNCTION__)); LogRel(a); } while (0)
931
932/** @def LogRelThisFunc
933 * The same as LogRelFunc but for class functions (methods): the resulting log
934 * line is additionally prepended with a hex value of |this| pointer.
935 */
936#define LogRelThisFunc(a) \
937 do { LogRel(("{%p} " LOG_FN_FMT ": ", this, __PRETTY_FUNCTION__)); LogRel(a); } while (0)
938
939/** @def LogRelLelik
940 * lelik logging.
941 */
942#define LogRelLelik(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LELIK, LOG_GROUP, a)
943
944/** @def LogRelMichael
945 * michael logging.
946 */
947#define LogRelMichael(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_MICHAEL, LOG_GROUP, a)
948
949/** @def LogRelDmik
950 * dmik logging.
951 */
952#define LogRelDmik(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_DMIK, LOG_GROUP, a)
953
954/** @def LogRelSunlover
955 * sunlover logging.
956 */
957#define LogRelSunlover(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_SUNLOVER, LOG_GROUP, a)
958
959/** @def LogRelAchim
960 * Achim logging.
961 */
962#define LogRelAchim(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_ACHIM, LOG_GROUP, a)
963
964/** @def LogRelSander
965 * Sander logging.
966 */
967#define LogRelSander(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_SANDER, LOG_GROUP, a)
968
969/** @def LogRelKlaus
970 * klaus logging.
971 */
972#define LogRelKlaus(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_KLAUS, LOG_GROUP, a)
973
974/** @def LogRelFrank
975 * frank logging.
976 */
977#define LogRelFrank(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FRANK, LOG_GROUP, a)
978
979/** @def LogRelBird
980 * bird logging.
981 */
982#define LogRelBird(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_BIRD, LOG_GROUP, a)
983
984/** @def LogRelNoName
985 * NoName logging.
986 */
987#define LogRelNoName(a) LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_NONAME, LOG_GROUP, a)
988
989
990/** @def LogRelIsItEnabled
991 * Checks whether the specified logging group is enabled or not.
992 */
993#define LogRelIsItEnabled(pvInst, fFlags, iGroup) \
994 LogRelIsItEnabledInternal((pvInst), (unsigned)(iGroup), (unsigned)(fFlags))
995
996/** @def LogRelIsEnabled
997 * Checks whether level 1 logging is enabled.
998 */
999#define LogRelIsEnabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP)
1000
1001/** @def LogRelIs2Enabled
1002 * Checks whether level 2 logging is enabled.
1003 */
1004#define LogRelIs2Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP)
1005
1006/** @def LogRelIs3Enabled
1007 * Checks whether level 3 logging is enabled.
1008 */
1009#define LogRelIs3Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_3, LOG_GROUP)
1010
1011/** @def LogRelIs4Enabled
1012 * Checks whether level 4 logging is enabled.
1013 */
1014#define LogRelIs4Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_4, LOG_GROUP)
1015
1016/** @def LogRelIs5Enabled
1017 * Checks whether level 5 logging is enabled.
1018 */
1019#define LogRelIs5Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_5, LOG_GROUP)
1020
1021/** @def LogRelIs6Enabled
1022 * Checks whether level 6 logging is enabled.
1023 */
1024#define LogRelIs6Enabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_6, LOG_GROUP)
1025
1026/** @def LogRelIsFlowEnabled
1027 * Checks whether execution flow logging is enabled.
1028 */
1029#define LogRelIsFlowEnabled() LogRelIsItEnabled(LOG_REL_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP)
1030
1031
1032#ifndef IN_RC
1033/**
1034 * Sets the default release logger instance.
1035 *
1036 * @returns The old default instance.
1037 * @param pLogger The new default release logger instance.
1038 */
1039RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger);
1040#endif /* !IN_RC */
1041
1042/**
1043 * Gets the default release logger instance.
1044 *
1045 * @returns Pointer to default release logger instance.
1046 * @returns NULL if no default release logger instance available.
1047 */
1048RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void);
1049
1050/** Internal worker function.
1051 * Don't call directly, use the LogRelIsItEnabled macro!
1052 */
1053DECLINLINE(bool) LogRelIsItEnabledInternal(void *pvInst, unsigned iGroup, unsigned fFlags)
1054{
1055 register PRTLOGGER pLogger = (PRTLOGGER)pvInst ? (PRTLOGGER)pvInst : RTLogRelDefaultInstance();
1056 if (pLogger)
1057 {
1058 register unsigned fGrpFlags = pLogger->afGroups[(unsigned)iGroup < pLogger->cGroups ? (unsigned)iGroup : 0];
1059 if ((fGrpFlags & (fFlags | RTLOGGRPFLAGS_ENABLED)) == (fFlags | RTLOGGRPFLAGS_ENABLED))
1060 return true;
1061 }
1062 return false;
1063}
1064
1065/**
1066 * Write to a logger instance, defaulting to the release one.
1067 *
1068 * This function will check whether the instance, group and flags makes up a
1069 * logging kind which is currently enabled before writing anything to the log.
1070 *
1071 * @param pLogger Pointer to logger instance.
1072 * @param fFlags The logging flags.
1073 * @param iGroup The group.
1074 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1075 * only for internal usage!
1076 * @param pszFormat Format string.
1077 * @param ... Format arguments.
1078 * @remark This is a worker function for LogRelIt.
1079 */
1080RTDECL(void) RTLogRelLogger(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
1081
1082/**
1083 * Write to a logger instance, defaulting to the release one.
1084 *
1085 * This function will check whether the instance, group and flags makes up a
1086 * logging kind which is currently enabled before writing anything to the log.
1087 *
1088 * @param pLogger Pointer to logger instance. If NULL the default release instance is attempted.
1089 * @param fFlags The logging flags.
1090 * @param iGroup The group.
1091 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1092 * only for internal usage!
1093 * @param pszFormat Format string.
1094 * @param args Format arguments.
1095 */
1096RTDECL(void) RTLogRelLoggerV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
1097
1098/**
1099 * printf like function for writing to the default release log.
1100 *
1101 * @param pszFormat Printf like format string.
1102 * @param ... Optional arguments as specified in pszFormat.
1103 *
1104 * @remark The API doesn't support formatting of floating point numbers at the moment.
1105 */
1106RTDECL(void) RTLogRelPrintf(const char *pszFormat, ...);
1107
1108/**
1109 * vprintf like function for writing to the default release log.
1110 *
1111 * @param pszFormat Printf like format string.
1112 * @param args Optional arguments as specified in pszFormat.
1113 *
1114 * @remark The API doesn't support formatting of floating point numbers at the moment.
1115 */
1116RTDECL(void) RTLogRelPrintfV(const char *pszFormat, va_list args);
1117
1118
1119/** @} */
1120
1121
1122
1123/** @name COM port logging
1124 * {
1125 */
1126
1127#ifdef DOXYGEN_RUNNING
1128# define LOG_TO_COM
1129# define LOG_NO_COM
1130#endif
1131
1132/** @def LOG_TO_COM
1133 * Redirects the normal loging macros to the serial versions.
1134 */
1135
1136/** @def LOG_NO_COM
1137 * Disables all LogCom* macros.
1138 */
1139
1140/** @def LogCom
1141 * Generic logging to serial port.
1142 */
1143#if defined(LOG_ENABLED) && !defined(LOG_NO_COM)
1144# define LogCom(a) RTLogComPrintf a
1145#else
1146# define LogCom(a) do { } while (0)
1147#endif
1148
1149/** @def LogComFlow
1150 * Logging to serial port of execution flow.
1151 */
1152#if defined(LOG_ENABLED) && defined(LOG_ENABLE_FLOW) && !defined(LOG_NO_COM)
1153# define LogComFlow(a) RTLogComPrintf a
1154#else
1155# define LogComFlow(a) do { } while (0)
1156#endif
1157
1158#ifdef LOG_TO_COM
1159# undef Log
1160# define Log(a) LogCom(a)
1161# undef LogFlow
1162# define LogFlow(a) LogComFlow(a)
1163#endif
1164
1165/** @} */
1166
1167
1168/** @name Backdoor Logging
1169 * @{
1170 */
1171
1172#ifdef DOXYGEN_RUNNING
1173# define LOG_TO_BACKDOOR
1174# define LOG_NO_BACKDOOR
1175#endif
1176
1177/** @def LOG_TO_BACKDOOR
1178 * Redirects the normal logging macros to the backdoor versions.
1179 */
1180
1181/** @def LOG_NO_BACKDOOR
1182 * Disables all LogBackdoor* macros.
1183 */
1184
1185/** @def LogBackdoor
1186 * Generic logging to the VBox backdoor via port I/O.
1187 */
1188#if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
1189# define LogBackdoor(a) RTLogBackdoorPrintf a
1190#else
1191# define LogBackdoor(a) do { } while (0)
1192#endif
1193
1194/** @def LogBackdoorFlow
1195 * Logging of execution flow messages to the backdoor I/O port.
1196 */
1197#if defined(LOG_ENABLED) && !defined(LOG_NO_BACKDOOR)
1198# define LogBackdoorFlow(a) RTLogBackdoorPrintf a
1199#else
1200# define LogBackdoorFlow(a) do { } while (0)
1201#endif
1202
1203/** @def LogRelBackdoor
1204 * Release logging to the VBox backdoor via port I/O.
1205 */
1206#if !defined(LOG_NO_BACKDOOR)
1207# define LogRelBackdoor(a) RTLogBackdoorPrintf a
1208#else
1209# define LogRelBackdoor(a) do { } while (0)
1210#endif
1211
1212#ifdef LOG_TO_BACKDOOR
1213# undef Log
1214# define Log(a) LogBackdoor(a)
1215# undef LogFlow
1216# define LogFlow(a) LogBackdoorFlow(a)
1217# undef LogRel
1218# define LogRel(a) LogRelBackdoor(a)
1219# if defined(LOG_USE_C99)
1220# undef _LogIt
1221# define _LogIt(pvInst, fFlags, iGroup, ...) LogBackdoor((__VA_ARGS__))
1222# endif
1223#endif
1224
1225/** @} */
1226
1227
1228
1229/**
1230 * Gets the default logger instance, creating it if necessary.
1231 *
1232 * @returns Pointer to default logger instance.
1233 * @returns NULL if no default logger instance available.
1234 */
1235RTDECL(PRTLOGGER) RTLogDefaultInstance(void);
1236
1237/**
1238 * Gets the default logger instance.
1239 *
1240 * @returns Pointer to default logger instance.
1241 * @returns NULL if no default logger instance available.
1242 */
1243RTDECL(PRTLOGGER) RTLogGetDefaultInstance(void);
1244
1245#ifndef IN_RC
1246/**
1247 * Sets the default logger instance.
1248 *
1249 * @returns The old default instance.
1250 * @param pLogger The new default logger instance.
1251 */
1252RTDECL(PRTLOGGER) RTLogSetDefaultInstance(PRTLOGGER pLogger);
1253#endif /* !IN_RC */
1254
1255#ifdef IN_RING0
1256/**
1257 * Changes the default logger instance for the current thread.
1258 *
1259 * @returns IPRT status code.
1260 * @param pLogger The logger instance. Pass NULL for deregistration.
1261 * @param uKey Associated key for cleanup purposes. If pLogger is NULL,
1262 * all instances with this key will be deregistered. So in
1263 * order to only deregister the instance associated with the
1264 * current thread use 0.
1265 */
1266RTDECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
1267#endif /* IN_RING0 */
1268
1269
1270#ifdef LOG_ENABLED
1271/** Internal worker function.
1272 * Don't call directly, use the LogIsItEnabled macro!
1273 */
1274DECLINLINE(bool) LogIsItEnabledInternal(void *pvInst, unsigned iGroup, unsigned fFlags)
1275{
1276 register PRTLOGGER pLogger = (PRTLOGGER)pvInst ? (PRTLOGGER)pvInst : RTLogDefaultInstance();
1277 if (pLogger)
1278 {
1279 register unsigned fGrpFlags = pLogger->afGroups[(unsigned)iGroup < pLogger->cGroups ? (unsigned)iGroup : 0];
1280 if ((fGrpFlags & (fFlags | RTLOGGRPFLAGS_ENABLED)) == (fFlags | RTLOGGRPFLAGS_ENABLED))
1281 return true;
1282 }
1283 return false;
1284}
1285#endif
1286
1287
1288#ifndef IN_RC
1289/**
1290 * Creates the default logger instance for a iprt users.
1291 *
1292 * Any user of the logging features will need to implement
1293 * this or use the generic dummy.
1294 *
1295 * @returns Pointer to the logger instance.
1296 */
1297RTDECL(PRTLOGGER) RTLogDefaultInit(void);
1298
1299/**
1300 * Create a logger instance.
1301 *
1302 * @returns iprt status code.
1303 *
1304 * @param ppLogger Where to store the logger instance.
1305 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1306 * @param pszGroupSettings The initial group settings.
1307 * @param pszEnvVarBase Base name for the environment variables for this instance.
1308 * @param cGroups Number of groups in the array.
1309 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1310 * logger instance.
1311 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1312 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1313 * @param ... Format arguments.
1314 */
1315RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1316 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1317 RTUINT fDestFlags, const char *pszFilenameFmt, ...);
1318
1319/**
1320 * Create a logger instance.
1321 *
1322 * @returns iprt status code.
1323 *
1324 * @param ppLogger Where to store the logger instance.
1325 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1326 * @param pszGroupSettings The initial group settings.
1327 * @param pszEnvVarBase Base name for the environment variables for this instance.
1328 * @param cGroups Number of groups in the array.
1329 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1330 * logger instance.
1331 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1332 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
1333 * @param cchErrorMsg The size of the error message buffer.
1334 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1335 * @param ... Format arguments.
1336 */
1337RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1338 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1339 RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...);
1340
1341/**
1342 * Create a logger instance.
1343 *
1344 * @returns iprt status code.
1345 *
1346 * @param ppLogger Where to store the logger instance.
1347 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1348 * @param pszGroupSettings The initial group settings.
1349 * @param pszEnvVarBase Base name for the environment variables for this instance.
1350 * @param cGroups Number of groups in the array.
1351 * @param papszGroups Pointer to array of groups. This must stick around for the life of the
1352 * logger instance.
1353 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.
1354 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.
1355 * @param cchErrorMsg The size of the error message buffer.
1356 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().
1357 * @param args Format arguments.
1358 */
1359RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings,
1360 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups,
1361 RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args);
1362
1363/**
1364 * Create a logger instance for singled threaded ring-0 usage.
1365 *
1366 * @returns iprt status code.
1367 *
1368 * @param pLogger Where to create the logger instance.
1369 * @param cbLogger The amount of memory available for the logger instance.
1370 * @param pfnLogger Pointer to logger wrapper function for the clone.
1371 * @param pfnFlush Pointer to flush function for the clone.
1372 * @param fFlags Logger instance flags for the clone, a combination of the RTLOGFLAGS_* values.
1373 * @param fDestFlags The destination flags.
1374 */
1375RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger, PFNRTLOGGER pfnLogger, PFNRTLOGFLUSH pfnFlush, RTUINT fFlags, RTUINT fDestFlags);
1376
1377/**
1378 * Destroys a logger instance.
1379 *
1380 * The instance is flushed and all output destinations closed (where applicable).
1381 *
1382 * @returns iprt status code.
1383 * @param pLogger The logger instance which close destroyed. NULL is fine.
1384 */
1385RTDECL(int) RTLogDestroy(PRTLOGGER pLogger);
1386
1387/**
1388 * Create a logger instance clone for RC usage.
1389 *
1390 * @returns iprt status code.
1391 *
1392 * @param pLogger The logger instance to be cloned.
1393 * @param pLoggerRC Where to create the RC logger instance.
1394 * @param cbLoggerRC Amount of memory allocated to for the RC logger
1395 * instance clone.
1396 * @param pfnLoggerRCPtr Pointer to logger wrapper function for this
1397 * instance (RC Ptr).
1398 * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).
1399 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.
1400 */
1401RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,
1402 RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, RTUINT fFlags);
1403
1404/**
1405 * Flushes a RC logger instance to a R3 logger.
1406 *
1407 * @returns iprt status code.
1408 * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL
1409 * the default logger is used.
1410 * @param pLoggerRC The RC logger instance to flush.
1411 */
1412RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC);
1413
1414/**
1415 * Flushes the buffer in one logger instance onto another logger.
1416 *
1417 * @returns iprt status code.
1418 *
1419 * @param pSrcLogger The logger instance to flush.
1420 * @param pDstLogger The logger instance to flush onto.
1421 * If NULL the default logger will be used.
1422 */
1423RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger);
1424
1425/**
1426 * Sets the custom prefix callback.
1427 *
1428 * @returns IPRT status code.
1429 * @param pLogger The logger instance.
1430 * @param pfnCallback The callback.
1431 * @param pvUser The user argument for the callback.
1432 * */
1433RTDECL(int) RTLogSetCustomPrefixCallback(PRTLOGGER pLogger, PFNRTLOGPREFIX pfnCallback, void *pvUser);
1434
1435/**
1436 * Copies the group settings and flags from logger instance to another.
1437 *
1438 * @returns IPRT status code.
1439 * @param pDstLogger The destination logger instance.
1440 * @param pSrcLogger The source logger instance. If NULL the default one is used.
1441 * @param fFlagsOr OR mask for the flags.
1442 * @param fFlagsAnd AND mask for the flags.
1443 */
1444RTDECL(int) RTLogCopyGroupsAndFlags(PRTLOGGER pDstLogger, PCRTLOGGER pSrcLogger, unsigned fFlagsOr, unsigned fFlagsAnd);
1445
1446/**
1447 * Updates the group settings for the logger instance using the specified
1448 * specification string.
1449 *
1450 * @returns iprt status code.
1451 * Failures can safely be ignored.
1452 * @param pLogger Logger instance (NULL for default logger).
1453 * @param pszVar Value to parse.
1454 */
1455RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszVar);
1456#endif /* !IN_RC */
1457
1458/**
1459 * Updates the flags for the logger instance using the specified
1460 * specification string.
1461 *
1462 * @returns iprt status code.
1463 * Failures can safely be ignored.
1464 * @param pLogger Logger instance (NULL for default logger).
1465 * @param pszVar Value to parse.
1466 */
1467RTDECL(int) RTLogFlags(PRTLOGGER pLogger, const char *pszVar);
1468
1469/**
1470 * Flushes the specified logger.
1471 *
1472 * @param pLogger The logger instance to flush.
1473 * If NULL the default instance is used. The default instance
1474 * will not be initialized by this call.
1475 */
1476RTDECL(void) RTLogFlush(PRTLOGGER pLogger);
1477
1478/**
1479 * Write to a logger instance.
1480 *
1481 * @param pLogger Pointer to logger instance.
1482 * @param pvCallerRet Ignored.
1483 * @param pszFormat Format string.
1484 * @param ... Format arguments.
1485 */
1486RTDECL(void) RTLogLogger(PRTLOGGER pLogger, void *pvCallerRet, const char *pszFormat, ...);
1487
1488/**
1489 * Write to a logger instance.
1490 *
1491 * @param pLogger Pointer to logger instance.
1492 * @param pszFormat Format string.
1493 * @param args Format arguments.
1494 */
1495RTDECL(void) RTLogLoggerV(PRTLOGGER pLogger, const char *pszFormat, va_list args);
1496
1497/**
1498 * Write to a logger instance.
1499 *
1500 * This function will check whether the instance, group and flags makes up a
1501 * logging kind which is currently enabled before writing anything to the log.
1502 *
1503 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
1504 * @param fFlags The logging flags.
1505 * @param iGroup The group.
1506 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1507 * only for internal usage!
1508 * @param pszFormat Format string.
1509 * @param ... Format arguments.
1510 * @remark This is a worker function of LogIt.
1511 */
1512RTDECL(void) RTLogLoggerEx(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
1513
1514/**
1515 * Write to a logger instance.
1516 *
1517 * This function will check whether the instance, group and flags makes up a
1518 * logging kind which is currently enabled before writing anything to the log.
1519 *
1520 * @param pLogger Pointer to logger instance. If NULL the default logger instance will be attempted.
1521 * @param fFlags The logging flags.
1522 * @param iGroup The group.
1523 * The value ~0U is reserved for compatability with RTLogLogger[V] and is
1524 * only for internal usage!
1525 * @param pszFormat Format string.
1526 * @param args Format arguments.
1527 */
1528RTDECL(void) RTLogLoggerExV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);
1529
1530/**
1531 * printf like function for writing to the default log.
1532 *
1533 * @param pszFormat Printf like format string.
1534 * @param ... Optional arguments as specified in pszFormat.
1535 *
1536 * @remark The API doesn't support formatting of floating point numbers at the moment.
1537 */
1538RTDECL(void) RTLogPrintf(const char *pszFormat, ...);
1539
1540/**
1541 * vprintf like function for writing to the default log.
1542 *
1543 * @param pszFormat Printf like format string.
1544 * @param args Optional arguments as specified in pszFormat.
1545 *
1546 * @remark The API doesn't support formatting of floating point numbers at the moment.
1547 */
1548RTDECL(void) RTLogPrintfV(const char *pszFormat, va_list args);
1549
1550
1551#ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/string.h */
1552#define DECLARED_FNRTSTROUTPUT
1553/**
1554 * Output callback.
1555 *
1556 * @returns number of bytes written.
1557 * @param pvArg User argument.
1558 * @param pachChars Pointer to an array of utf-8 characters.
1559 * @param cbChars Number of bytes in the character array pointed to by pachChars.
1560 */
1561typedef DECLCALLBACK(size_t) FNRTSTROUTPUT(void *pvArg, const char *pachChars, size_t cbChars);
1562/** Pointer to callback function. */
1563typedef FNRTSTROUTPUT *PFNRTSTROUTPUT;
1564#endif
1565
1566/**
1567 * Partial vsprintf worker implementation.
1568 *
1569 * @returns number of bytes formatted.
1570 * @param pfnOutput Output worker.
1571 * Called in two ways. Normally with a string an it's length.
1572 * For termination, it's called with NULL for string, 0 for length.
1573 * @param pvArg Argument to output worker.
1574 * @param pszFormat Format string.
1575 * @param args Argument list.
1576 */
1577RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args);
1578
1579/**
1580 * Write log buffer to COM port.
1581 *
1582 * @param pach Pointer to the buffer to write.
1583 * @param cb Number of bytes to write.
1584 */
1585RTDECL(void) RTLogWriteCom(const char *pach, size_t cb);
1586
1587/**
1588 * Prints a formatted string to the serial port used for logging.
1589 *
1590 * @returns Number of bytes written.
1591 * @param pszFormat Format string.
1592 * @param ... Optional arguments specified in the format string.
1593 */
1594RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...);
1595
1596/**
1597 * Prints a formatted string to the serial port used for logging.
1598 *
1599 * @returns Number of bytes written.
1600 * @param pszFormat Format string.
1601 * @param args Optional arguments specified in the format string.
1602 */
1603RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args);
1604
1605
1606#if 0 /* not implemented yet */
1607
1608/** Indicates that the semaphores shall be used to notify the other
1609 * part about buffer changes. */
1610#define LOGHOOKBUFFER_FLAGS_SEMAPHORED 1
1611
1612/**
1613 * Log Hook Buffer.
1614 * Use to commuicate between the logger and a log consumer.
1615 */
1616typedef struct RTLOGHOOKBUFFER
1617{
1618 /** Write pointer. */
1619 volatile void *pvWrite;
1620 /** Read pointer. */
1621 volatile void *pvRead;
1622 /** Buffer start. */
1623 void *pvStart;
1624 /** Buffer end (exclusive). */
1625 void *pvEnd;
1626 /** Signaling semaphore used by the writer to wait on a full buffer.
1627 * Only used when indicated in flags. */
1628 void *pvSemWriter;
1629 /** Signaling semaphore used by the read to wait on an empty buffer.
1630 * Only used when indicated in flags. */
1631 void *pvSemReader;
1632 /** Buffer flags. Current reserved and set to zero. */
1633 volatile unsigned fFlags;
1634} RTLOGHOOKBUFFER;
1635/** Pointer to a log hook buffer. */
1636typedef RTLOGHOOKBUFFER *PRTLOGHOOKBUFFER;
1637
1638
1639/**
1640 * Register a logging hook.
1641 *
1642 * This type of logging hooks are expecting different threads acting
1643 * producer and consumer. They share a circular buffer which have two
1644 * pointers one for each end. When the buffer is full there are two
1645 * alternatives (indicated by a buffer flag), either wait for the
1646 * consumer to get it's job done, or to write a generic message saying
1647 * buffer overflow.
1648 *
1649 * Since the waiting would need a signal semaphore, we'll skip that for now.
1650 *
1651 * @returns iprt status code.
1652 * @param pBuffer Pointer to a logger hook buffer.
1653 */
1654RTDECL(int) RTLogRegisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
1655
1656/**
1657 * Deregister a logging hook registerd with RTLogRegisterHook().
1658 *
1659 * @returns iprt status code.
1660 * @param pBuffer Pointer to a logger hook buffer.
1661 */
1662RTDECL(int) RTLogDeregisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);
1663
1664#endif /* not implemented yet */
1665
1666
1667
1668/**
1669 * Write log buffer to a debugger (RTLOGDEST_DEBUGGER).
1670 *
1671 * @param pach What to write.
1672 * @param cb How much to write.
1673 * @remark When linking statically, this function can be replaced by defining your own.
1674 */
1675RTDECL(void) RTLogWriteDebugger(const char *pach, size_t cb);
1676
1677/**
1678 * Write log buffer to a user defined output stream (RTLOGDEST_USER).
1679 *
1680 * @param pach What to write.
1681 * @param cb How much to write.
1682 * @remark When linking statically, this function can be replaced by defining your own.
1683 */
1684RTDECL(void) RTLogWriteUser(const char *pach, size_t cb);
1685
1686/**
1687 * Write log buffer to stdout (RTLOGDEST_STDOUT).
1688 *
1689 * @param pach What to write.
1690 * @param cb How much to write.
1691 * @remark When linking statically, this function can be replaced by defining your own.
1692 */
1693RTDECL(void) RTLogWriteStdOut(const char *pach, size_t cb);
1694
1695/**
1696 * Write log buffer to stdout (RTLOGDEST_STDERR).
1697 *
1698 * @param pach What to write.
1699 * @param cb How much to write.
1700 * @remark When linking statically, this function can be replaced by defining your own.
1701 */
1702RTDECL(void) RTLogWriteStdErr(const char *pach, size_t cb);
1703
1704#ifdef VBOX
1705
1706/**
1707 * Prints a formatted string to the backdoor port.
1708 *
1709 * @returns Number of bytes written.
1710 * @param pszFormat Format string.
1711 * @param ... Optional arguments specified in the format string.
1712 */
1713RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...);
1714
1715/**
1716 * Prints a formatted string to the backdoor port.
1717 *
1718 * @returns Number of bytes written.
1719 * @param pszFormat Format string.
1720 * @param args Optional arguments specified in the format string.
1721 */
1722RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args);
1723
1724#endif /* VBOX */
1725
1726RT_C_DECLS_END
1727
1728/** @} */
1729
1730#endif
1731
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