1 | /* $Id: logformat.cpp 628 2007-02-05 11:59:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime - Log Formatter.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <iprt/log.h>
|
---|
27 | #include <iprt/string.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #ifdef IN_RING3
|
---|
30 | # include <iprt/thread.h>
|
---|
31 | # include <iprt/err.h>
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/stdarg.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /*******************************************************************************
|
---|
39 | * Internal Functions *
|
---|
40 | *******************************************************************************/
|
---|
41 | static DECLCALLBACK(int) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput,
|
---|
42 | void *pvArgOutput, const char **ppszFormat,
|
---|
43 | va_list *pArgs, int cchWidth, int cchPrecision,
|
---|
44 | unsigned fFlags, char chArgSize);
|
---|
45 |
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Partial vsprintf worker implementation.
|
---|
49 | *
|
---|
50 | * @returns number of bytes formatted.
|
---|
51 | * @param pfnOutput Output worker.
|
---|
52 | * Called in two ways. Normally with a string an it's length.
|
---|
53 | * For termination, it's called with NULL for string, 0 for length.
|
---|
54 | * @param pvArg Argument to output worker.
|
---|
55 | * @param pszFormat Format string.
|
---|
56 | * @param args Argument list.
|
---|
57 | */
|
---|
58 | RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args)
|
---|
59 | {
|
---|
60 | return RTStrFormatV(pfnOutput, pvArg, rtlogFormatStr, NULL, pszFormat, args);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Callback to format VBox formatting extentions.
|
---|
66 | * See @ref pg_rt_str_format_rt for a reference on the format types.
|
---|
67 | *
|
---|
68 | * @returns The number of bytes formatted.
|
---|
69 | * @param pvArg Formatter argument.
|
---|
70 | * @param pfnOutput Pointer to output function.
|
---|
71 | * @param pvArgOutput Argument for the output function.
|
---|
72 | * @param ppszFormat Pointer to the format string pointer. Advance this till the char
|
---|
73 | * after the format specifier.
|
---|
74 | * @param pArgs Pointer to the argument list. Use this to fetch the arguments.
|
---|
75 | * @param cchWidth Format Width. -1 if not specified.
|
---|
76 | * @param cchPrecision Format Precision. -1 if not specified.
|
---|
77 | * @param fFlags Flags (RTSTR_NTFS_*).
|
---|
78 | * @param chArgSize The argument size specifier, 'l' or 'L'.
|
---|
79 | */
|
---|
80 | static DECLCALLBACK(int) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
|
---|
81 | const char **ppszFormat, va_list *pArgs, int cchWidth, int cchPrecision, unsigned fFlags, char chArgSize)
|
---|
82 | {
|
---|
83 | char ch = *(*ppszFormat)++;
|
---|
84 |
|
---|
85 | AssertMsgFailed(("Invalid logger format type '%%%c%.10s'!\n", ch, *ppszFormat)); NOREF(ch);
|
---|
86 |
|
---|
87 | return 0;
|
---|
88 | }
|
---|
89 |
|
---|