VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/log/logformat.cpp@ 104286

Last change on this file since 104286 was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.7 KB
Line 
1/* $Id: logformat.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Log Formatter.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/log.h>
42#include "internal/iprt.h"
43
44#include <iprt/string.h>
45#include <iprt/assert.h>
46#ifdef IN_RING3
47# include <iprt/thread.h>
48# include <iprt/errcore.h>
49#endif
50
51#include <iprt/stdarg.h>
52#include <iprt/string.h>
53
54
55/*********************************************************************************************************************************
56* Internal Functions *
57*********************************************************************************************************************************/
58static DECLCALLBACK(size_t) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput,
59 void *pvArgOutput, const char **ppszFormat,
60 va_list *pArgs, int cchWidth, int cchPrecision,
61 unsigned fFlags, char chArgSize);
62
63
64/**
65 * Partial vsprintf worker implementation.
66 *
67 * @returns number of bytes formatted.
68 * @param pfnOutput Output worker.
69 * Called in two ways. Normally with a string an it's length.
70 * For termination, it's called with NULL for string, 0 for length.
71 * @param pvArg Argument to output worker.
72 * @param pszFormat Format string.
73 * @param args Argument list.
74 */
75RTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args)
76{
77 return RTStrFormatV(pfnOutput, pvArg, rtlogFormatStr, NULL, pszFormat, args);
78}
79RT_EXPORT_SYMBOL(RTLogFormatV);
80
81
82/**
83 * Callback to format VBox formatting extentions.
84 * See @ref pg_rt_str_format for a reference on the format types.
85 *
86 * @returns The number of bytes formatted.
87 * @param pvArg Formatter argument.
88 * @param pfnOutput Pointer to output function.
89 * @param pvArgOutput Argument for the output function.
90 * @param ppszFormat Pointer to the format string pointer. Advance this till the char
91 * after the format specifier.
92 * @param pArgs Pointer to the argument list. Use this to fetch the arguments.
93 * @param cchWidth Format Width. -1 if not specified.
94 * @param cchPrecision Format Precision. -1 if not specified.
95 * @param fFlags Flags (RTSTR_NTFS_*).
96 * @param chArgSize The argument size specifier, 'l' or 'L'.
97 */
98static DECLCALLBACK(size_t) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
99 const char **ppszFormat, va_list *pArgs, int cchWidth,
100 int cchPrecision, unsigned fFlags, char chArgSize)
101{
102 char ch = *(*ppszFormat)++;
103
104 AssertMsgFailed(("Invalid logger format type '%%%c%.10s'!\n", ch, *ppszFormat)); NOREF(ch);
105
106 NOREF(pvArg); NOREF(pfnOutput); NOREF(pvArgOutput); NOREF(pArgs); NOREF(cchWidth);
107 NOREF(cchPrecision); NOREF(fFlags); NOREF(chArgSize);
108 return 0;
109}
110
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use