log-vbox.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* VirtualBox Runtime - Logging configuration.
*/
/*
* Copyright (C) 2006-2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/** @page pg_rtlog Runtime - Logging
*
* VBox uses the IPRT logging system which supports group level flags and multiple
* destinations. The GC logging is making it even more interesting since GC logging will
* have to be buffered and written when back in host context.
*
* [more later]
*
*
* @section sec_logging_destination The Destination Specifier.
*
* The {logger-env-base}_DEST environment variable can be used to specify where
* the log output goes. The following specifiers are recognized:
*
* - file=\<filename\>
* This sets the logger output filename to \<filename\>. Not formatting
* or anything is supported. Each logger specifies a default name if
* file logging should be enabled by default.
*
* - nofile
* This disables the file output.
*
* - stdout
* Enables logger output to stdout.
*
* - nostdout
* Disables logger output to stdout.
*
* - stderr
* Enables logger output to stderr.
*
* - nostderr
* Disables logger output to stderr.
*
* - debugger
* Enables logger output to native debugger. (Win32/64 only)
*
* - nodebugger
* Disables logger output to native debugger. (Win32/64 only)
*
* - user
* Enables logger output to special backdoor if in guest r0.
*
* - nodebugger
* Disables logger output to special user stream.
*
*
*
* @section sec_logging_destination The Group Specifier.
*
* The {logger-env-base} environment variable can be used to specify which
* logger groups to enable and which to disable. By default all groups are
* disabled. For your convenience this specifier is case in-sensitive (ASCII).
*
* The specifier is evaluated from left to right.
*
* [more later]
*
* The groups settings can be reprogrammed during execution using the
* RTLogGroupSettings() command and a group specifier.
*
*
*
* @section sec_logging_default The Default Logger
*
* The default logger uses VBOX_LOG_DEST as destination specifier. File output is
* enabled by default and goes to a file "./VBox-\<pid\>.log".
*
* The default logger have all groups turned off by default to force the developer
* to be careful with what log information to collect - logging everything is
* generally NOT a good idea.
*
* The log groups of the default logger can be found in the LOGGROUP in enum. The
* VBOX_LOG environment variable and the .log debugger command can be used to
* configure the groups.
*
* be appended to the group name using dot separators. The flags correspond to
* RTLOGGRPFLAGS and have a short and a long version:
*
* - e - Enabled: Whether the group is enabled at all.
* - l - Level2: Level-2 logging.
* - f - Flow: Execution flow logging (entry messages)
* - s - Sander: Special Sander logging messages.
* - b - Bird: Special Bird logging messages.
*
* @todo Update this section...
*
* Example:
*
* VBOX_LOG=+all+pgm.e.s.b.z.l-qemu
*
* Space and ';' separators are allowed:
*
* VBOX_LOG=+all +pgm.e.s.b.z.l ; - qemu
*
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef IN_RING3
# if defined(RT_OS_WINDOWS)
# include <Windows.h>
# elif defined(RT_OS_LINUX)
# include <unistd.h>
# elif defined(RT_OS_FREEBSD)
# include <stdlib.h>
# include <unistd.h>
# elif defined(RT_OS_SOLARIS)
# define _STRUCTURED_PROC 1
# include <unistd.h>
# include <stdlib.h>
# endif
#endif
#ifdef IN_RING3
# include <stdio.h>
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The default logger. */
/** The default logger groups.
* This must match LOGGROUP! */
static const char *g_apszGroups[] =
/**
* Creates the default logger instance for a VBox process.
*
* @returns Pointer to the logger instance.
*/
{
/*
* Initialize the default logger instance.
* Take care to do this once and not recursivly.
*/
static volatile uint32_t fInitializing = 0;
int rc;
return g_pLogger;
#ifdef IN_RING3
/*
* Assert the group definitions.
*/
do { if (strcmp(g_apszGroups[def], str)) {printf("%s='%s' expects '%s'\n", #def, g_apszGroups[def], str); RTAssertDoPanic(); } } while (0)
#endif /* IN_RING3 */
/*
* Create the default logging instance.
*/
#ifdef IN_RING3
# ifndef IN_GUEST
char szExecName[RTPATH_MAX];
rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_FILE,
"./%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
Time.i32Year, Time.u8Month, Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second, Time.u32Nanosecond / 10000000,
if (RT_SUCCESS(rc))
{
/*
* Write a log header.
*/
char szBuf[RTPATH_MAX];
/* executable and arguments - tricky and all platform specific. */
# if defined(RT_OS_WINDOWS)
# elif defined(RT_OS_SOLARIS)
char szArgFileBuf[80];
if (pFile)
{
{
# if 0 /* 100% safe:*/
# else /* probably safe: */
# endif
}
}
# elif defined(RT_OS_LINUX)
if (pFile)
{
/* braindead */
unsigned iArg = 0;
char ch;
bool fNew = true;
{
if (fNew)
{
fNew = false;
}
if (ch)
else
{
fNew = true;
}
}
if (!fNew)
}
# elif defined(RT_OS_FREEBSD)
/* Retrieve the required length first */
int aiName[4];
if (cchArgs > 0)
{
if (pszArgFileBuf)
{
/* Retrieve the argument list */
if (!rcBSD)
{
unsigned iArg = 0;
{
/* advance */
iArg++;
}
}
}
}
/* commandline? */
# else
# endif
}
# else /* IN_GUEST */
/* The user destination is backdoor logging. */
RTLOGDEST_USER, "VBox.log");
# endif /* IN_GUEST */
#else /* IN_RING0 */
# ifndef IN_GUEST
rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_FILE, "VBox-ring0.log");
# else /* IN_GUEST */
rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_USER, "VBox-ring0.log");
# endif /* IN_GUEST */
if (RT_SUCCESS(rc))
{
/*
* This is where you set your ring-0 logging preferences.
*
* On platforms which don't differ between debugger and kernel
* log printing, STDOUT is gonna be a stub and the DEBUGGER
* destination is the one doing all the work. On platforms
* that do differ (like Darwin), STDOUT is the kernel log.
*/
# if defined(DEBUG_bird)
/*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
# ifndef IN_GUEST
# endif
# endif
# if defined(DEBUG_sandervl) && !defined(IN_GUEST)
# endif
# if defined(DEBUG_ramshankar) /* Guest ring-0 as well */
# endif
# if defined(DEBUG_aleksey) /* Guest ring-0 as well */
# endif
# if defined(DEBUG_andy) /* Guest ring-0 as well */
# endif
# if 0 /* defined(DEBUG_misha) */ /* Guest ring-0 as well */
# endif
# if 0 /* vboxdrv logging - ATTENTION: this is what we're refering to guys! Change to '# if 1'. */
# endif
}
#endif /* IN_RING0 */
}