diff options
Diffstat (limited to 'src/VBox/Main/src-server/Logging.cpp')
-rw-r--r-- | src/VBox/Main/src-server/Logging.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/VBox/Main/src-server/Logging.cpp b/src/VBox/Main/src-server/Logging.cpp new file mode 100644 index 000000000..148a50f5d --- /dev/null +++ b/src/VBox/Main/src-server/Logging.cpp @@ -0,0 +1,133 @@ +/* $Id: Logging.cpp 37666 2011-06-28 12:33:34Z vboxsync $ */ + +/** @file + * + * Logging in VBoxSVC. + */ + +/* + * Copyright (C) 2011 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * 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. + */ + +#include "Logging.h" + +#include <package-generated.h> + +#include <iprt/buildconfig.h> +#include <iprt/err.h> +#include <iprt/message.h> +#include <iprt/path.h> +#include <iprt/system.h> +#include <iprt/process.h> +#include <VBox/version.h> +#include <VBox/log.h> + + +static void vboxsvcHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) +{ + /* some introductory information */ + static RTTIMESPEC s_TimeSpec; + char szTmp[256]; + if (enmPhase == RTLOGPHASE_BEGIN) + RTTimeNow(&s_TimeSpec); + RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp)); + + switch (enmPhase) + { + case RTLOGPHASE_BEGIN: + { + pfnLog(pLoggerRelease, + "VirtualBox (XP)COM Server %s r%u %s (%s %s) release log\n" +#ifdef VBOX_BLEEDING_EDGE + "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n" +#endif + "Log opened %s\n", + VBOX_VERSION_STRING, RTBldCfgRevision(), VBOX_BUILD_TARGET, + __DATE__, __TIME__, szTmp); + + int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp); + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp); + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp); + + /* the package type is interesting for Linux distributions */ + char szExecName[RTPATH_MAX]; + char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName)); + pfnLog(pLoggerRelease, + "Executable: %s\n" + "Process ID: %u\n" + "Package type: %s" +#ifdef VBOX_OSE + " (OSE)" +#endif + "\n", + pszExecName ? pszExecName : "unknown", + RTProcSelf(), + VBOX_PACKAGE_STRING); + break; + } + + case RTLOGPHASE_PREROTATE: + pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp); + break; + + case RTLOGPHASE_POSTROTATE: + pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp); + break; + + case RTLOGPHASE_END: + pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp); + break; + + default: + /* nothing */; + } +} + +int VBoxSVCLogRelCreate(const char *pszLogFile, uint32_t cHistory, + uint32_t uHistoryFileTime, uint64_t uHistoryFileSize) +{ + /* create release logger */ + PRTLOGGER pLoggerReleaseFile; + static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; + RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG; +#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) + fFlags |= RTLOGFLAGS_USECRLF; +#endif + char szError[RTPATH_MAX + 128] = ""; + int vrc = RTLogCreateEx(&pLoggerReleaseFile, fFlags, "all", + "VBOXSVC_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups, 0 /* fDestFlags */, + vboxsvcHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime, + szError, sizeof(szError), pszLogFile); + if (RT_SUCCESS(vrc)) + { + /* register this logger as the release logger */ + RTLogRelSetDefaultInstance(pLoggerReleaseFile); + + /* Explicitly flush the log in case of VBOXWEBSRV_RELEASE_LOG=buffered. */ + RTLogFlush(pLoggerReleaseFile); + } + else + { + /* print a message, but do not fail */ + RTMsgError("failed to open release log (%s, %Rrc)", szError, vrc); + } + return vrc; +} + +/* vi: set tabstop=4 shiftwidth=4 expandtab: */ |