VirtualBox

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

Last change on this file since 7170 was 7170, checked in by vboxsync, 17 years ago

Doxygen fixes. (DOXYGEN -> DOXYGEN_RUNNING, ++)

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