logformat.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/* $Id$ */
2362N/A/** @file
0N/A * InnoTek Portable Runtime - Log Formatter.
0N/A */
0N/A
0N/A/*
0N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH
0N/A *
0N/A * This file is part of VirtualBox Open Source Edition (OSE), as
0N/A * available from http://www.virtualbox.org. This file is free software;
0N/A * you can redistribute it and/or modify it under the terms of the GNU
0N/A * General Public License as published by the Free Software Foundation,
0N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
0N/A * distribution. VirtualBox OSE is distributed in the hope that it will
0N/A * be useful, but WITHOUT ANY WARRANTY of any kind.
0N/A *
0N/A * If you received this file as part of a commercial VirtualBox
0N/A * distribution, then only the terms of your commercial VirtualBox
2362N/A * license agreement apply instead of the previous paragraph.
2362N/A */
2362N/A
0N/A
0N/A/*******************************************************************************
0N/A* Header Files *
0N/A*******************************************************************************/
0N/A#include <iprt/log.h>
0N/A#include <iprt/string.h>
0N/A#include <iprt/assert.h>
0N/A#ifdef IN_RING3
0N/A# include <iprt/thread.h>
0N/A# include <iprt/err.h>
0N/A#endif
0N/A
0N/A#include <iprt/stdarg.h>
0N/A#include <iprt/string.h>
0N/A
0N/A
0N/A/*******************************************************************************
0N/A* Internal Functions *
0N/A*******************************************************************************/
0N/Astatic DECLCALLBACK(int) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput,
0N/A void *pvArgOutput, const char **ppszFormat,
0N/A va_list *pArgs, int cchWidth, int cchPrecision,
0N/A unsigned fFlags, char chArgSize);
0N/A
0N/A
0N/A/**
0N/A * Partial vsprintf worker implementation.
0N/A *
0N/A * @returns number of bytes formatted.
0N/A * @param pfnOutput Output worker.
0N/A * Called in two ways. Normally with a string an it's length.
0N/A * For termiation, it's called with NULL for string, 0 for length.
0N/A * @param pvArg Argument to output worker.
0N/A * @param pszFormat Format string.
0N/A * @param args Argument list.
0N/A */
0N/ARTDECL(size_t) RTLogFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArg, const char *pszFormat, va_list args)
0N/A{
0N/A return RTStrFormatV(pfnOutput, pvArg, rtlogFormatStr, NULL, pszFormat, args);
0N/A}
0N/A
0N/A
0N/A/**
0N/A * Callback to format VBox formatting extentions.
0N/A * See @ref pg_rt_str_format_rt for a reference on the format types.
0N/A *
0N/A * @returns The number of bytes formatted.
0N/A * @param pvArg Formatter argument.
0N/A * @param pfnOutput Pointer to output function.
0N/A * @param pvArgOutput Argument for the output function.
0N/A * @param ppszFormat Pointer to the format string pointer. Advance this till the char
0N/A * after the format specifier.
* @param pArgs Pointer to the argument list. Use this to fetch the arguments.
* @param cchWidth Format Width. -1 if not specified.
* @param cchPrecision Format Precision. -1 if not specified.
* @param fFlags Flags (RTSTR_NTFS_*).
* @param chArgSize The argument size specifier, 'l' or 'L'.
*/
static DECLCALLBACK(int) rtlogFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
const char **ppszFormat, va_list *pArgs, int cchWidth, int cchPrecision, unsigned fFlags, char chArgSize)
{
char ch = *(*ppszFormat)++;
AssertMsgFailed(("Invalid logger format type '%%%c%.10s'!\n", ch, *ppszFormat)); NOREF(ch);
return 0;
}