summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2023-05-09 08:28:38 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2023-05-09 08:28:38 +0000
commit6c05158e0eafd9847b03de397bbde2c0b4d2f49e (patch)
tree9c84306665f492f7f7ab1ccb558bb188c59ceb13 /src
parent45da1ec9cdb1923f20ba78391c08936973db45b2 (diff)
downloadVirtualBox-svn-6c05158e0eafd9847b03de397bbde2c0b4d2f49e.tar.gz
Guest Additions/VBoxClient: Dropped the idea of having an own logging facility (VBGHLogXXX) for shared guest/host code again; the (release) logger is flexible enough for this. bugref:10427
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@99689 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src')
-rw-r--r--src/VBox/Additions/x11/VBoxClient/Makefile.kmk1
-rw-r--r--src/VBox/Additions/x11/VBoxClient/VBoxClient.h2
-rw-r--r--src/VBox/Additions/x11/VBoxClient/logging.cpp78
-rw-r--r--src/VBox/Additions/x11/VBoxClient/main.cpp30
-rw-r--r--src/VBox/Frontends/VirtualBox/Makefile.kmk1
-rw-r--r--src/VBox/GuestHost/DisplayServerType.cpp20
-rw-r--r--src/VBox/GuestHost/Log.cpp245
7 files changed, 89 insertions, 288 deletions
diff --git a/src/VBox/Additions/x11/VBoxClient/Makefile.kmk b/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
index ae854ac506a..00ab0850e7a 100644
--- a/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
+++ b/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
@@ -50,7 +50,6 @@ PROGRAMS.linux += VBoxDRMClient
# Common Guest / Host sources.
VBOX_GH_SOURCES := \
- $(PATH_ROOT)/src/VBox/GuestHost/Log.cpp \
$(PATH_ROOT)/src/VBox/GuestHost/DisplayServerType.cpp
VBoxClient_TEMPLATE = VBoxGuestR3Exe
diff --git a/src/VBox/Additions/x11/VBoxClient/VBoxClient.h b/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
index 1edf2f6d3a4..087b7c16266 100644
--- a/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
+++ b/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
@@ -36,7 +36,6 @@
#include <iprt/cpp/utils.h>
#include <iprt/string.h>
-#include <VBox/GuestHost/Log.h>
#include <VBox/GuestHost/DisplayServerType.h>
int VBClShowNotify(const char *pszHeader, const char *pszBody);
@@ -48,6 +47,7 @@ void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...);
int VBClLogCreate(const char *pszLogFile);
int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader);
+int VBClLogModify(const char *pszDest, unsigned uVerbosity);
void VBClLogSetLogPrefix(const char *pszPrefix);
void VBClLogDestroy(void);
diff --git a/src/VBox/Additions/x11/VBoxClient/logging.cpp b/src/VBox/Additions/x11/VBoxClient/logging.cpp
index ebd8cd13ba8..6c7dd168dd3 100644
--- a/src/VBox/Additions/x11/VBoxClient/logging.cpp
+++ b/src/VBox/Additions/x11/VBoxClient/logging.cpp
@@ -41,8 +41,6 @@
#endif
#include <VBox/VBoxGuestLib.h>
-#include <VBox/GuestHost/Log.h>
-
#include <package-generated.h>
#include "VBoxClient.h"
@@ -222,6 +220,22 @@ int VBClShowNotify(const char *pszHeader, const char *pszBody)
}
/**
+ * Logs a message with a given prefix, format string and a va_list.
+ *
+ * @param pszPrefix Log prefix to use.
+ * @param pszFormat Format string to use.
+ * @param va va_list to use.
+ */
+static void vbclLogV(const char *pszPrefix, const char *pszFormat, va_list va)
+{
+ char *psz = NULL;
+ RTStrAPrintfV(&psz, pszFormat, va);
+ AssertPtrReturnVoid(psz);
+ LogRel(("%s%s", pszPrefix ? pszPrefix : "", psz));
+ RTStrFree(psz);
+}
+
+/**
* Logs a fatal error, notifies the desktop environment via a message and
* exits the application immediately.
*
@@ -232,7 +246,7 @@ void VBClLogFatalError(const char *pszFormat, ...)
{
va_list va;
va_start(va, pszFormat);
- VBGHLogFatalErrorV(pszFormat, va);
+ vbclLogV("Fatal Error: ", pszFormat, va);
va_end(va);
}
@@ -245,7 +259,7 @@ void VBClLogError(const char *pszFormat, ...)
{
va_list va;
va_start(va, pszFormat);
- VBGHLogErrorV(pszFormat, va);
+ vbclLogV("Error: ", pszFormat, va);
va_end(va);
}
@@ -258,7 +272,7 @@ void VBClLogInfo(const char *pszFormat, ...)
{
va_list va;
va_start(va, pszFormat);
- VBGHLogInfoV(pszFormat, va);
+ vbclLogV("", pszFormat, va);
va_end(va);
}
@@ -274,7 +288,8 @@ void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...)
{
va_list va;
va_start(va, pszFormat);
- VBGHLogVerboseV(iLevel, pszFormat, va);
+ if (iLevel <= g_cVerbosity)
+ vbclLogV("", pszFormat, va);
va_end(va);
}
@@ -418,20 +433,57 @@ int VBClLogCreate(const char *pszLogFile)
}
/**
- * Set custom log prefix.
+ * Destroys the currently active logging instance.
+ */
+void VBClLogDestroy(void)
+{
+ RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
+}
+
+/**
+ * Modifies the (release) log settings.
*
- * @param pszPrefix Custom log prefix string.
+ * @returns VBox status code.
+ * @param pszDest Log destination string to set.
+ * @param uVerbosity Verbosity level to set.
+ *
+ * @note Errors will be logged to stderr.
*/
-void VBClLogSetLogPrefix(const char *pszPrefix)
+int VBClLogModify(const char *pszDest, unsigned uVerbosity)
{
- g_pszCustomLogPrefix = (char *)pszPrefix;
+ AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
+ AssertPtrReturn(g_pLoggerRelease, VERR_INVALID_POINTER);
+
+ int rc = RTLogDestinations(g_pLoggerRelease, pszDest);
+ if (RT_SUCCESS(rc))
+ {
+#define LOG_GROUP_SET_BREAK(a_Val) \
+ rc = RTLogGroupSettings(g_pLoggerRelease, "all.e" a_Val); break;
+
+ switch (uVerbosity)
+ {
+ case 0: LOG_GROUP_SET_BREAK("");
+ case 1: LOG_GROUP_SET_BREAK(".l");
+ case 2: LOG_GROUP_SET_BREAK(".l.l2");
+ case 3: LOG_GROUP_SET_BREAK(".l.l2.l3");
+ default: LOG_GROUP_SET_BREAK(".l.l2.l3.l4");
+ }
+#undef LOG_GROUP_SET_BREAK
+ }
+
+ if (RT_FAILURE(rc)) /* Print to stderr in the hope that anyone can read this. */
+ RTMsgError("Failed to set/modify log output, rc=%Rrc", rc);
+
+ return rc;
}
/**
- * Destroys the currently active logging instance.
+ * Set custom log prefix.
+ *
+ * @param pszPrefix Custom log prefix string.
*/
-void VBClLogDestroy(void)
+void VBClLogSetLogPrefix(const char *pszPrefix)
{
- RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
+ g_pszCustomLogPrefix = (char *)pszPrefix;
}
diff --git a/src/VBox/Additions/x11/VBoxClient/main.cpp b/src/VBox/Additions/x11/VBoxClient/main.cpp
index 60bde0899db..e9d680dbfd6 100644
--- a/src/VBox/Additions/x11/VBoxClient/main.cpp
+++ b/src/VBox/Additions/x11/VBoxClient/main.cpp
@@ -673,10 +673,15 @@ int main(int argc, char *argv[])
rc = VBClLogCreateEx("" /* No file logging */, false /* No header */);
if (RT_SUCCESS(rc))
{
- VBGHLogVerbositySet(2);
- VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect();
- VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType));
- return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
+ /* Make sure that we increase the verbosity (if needed), to gain some more insights
+ * when detecting the display server. */
+ rc = VBClLogModify("stdout", g_cVerbosity);
+ if (RT_SUCCESS(rc))
+ {
+ VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect();
+ VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType));
+ return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
+ }
}
return RTEXITCODE_FAILURE;
@@ -739,23 +744,14 @@ int main(int argc, char *argv[])
if (RT_FAILURE(rc))
return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogCreateEx(). */
- if (!fDaemonise)
- {
- /* If the user is running in "no daemon" mode, send critical logging to stdout as well. */
- PRTLOGGER pReleaseLog = RTLogRelGetDefaultInstance();
- if (pReleaseLog)
- {
- rc = RTLogDestinations(pReleaseLog, "stdout");
- if (RT_FAILURE(rc))
- return RTMsgErrorExitFailure("Failed to redivert error output, rc=%Rrc", rc);
- }
- }
+ /* If the user is running in "no daemon" mode, send critical logging to stdout as well. */
+ rc = VBClLogModify(fDaemonise ? "" : "stdout", g_cVerbosity);
+ if (RT_FAILURE(rc))
+ return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogModify(). */
VBClLogInfo("VBoxClient %s r%s started. Verbose level = %d\n",
RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity);
- VBGHLogVerbositySet(g_cVerbosity);
-
/* Try to detect the current session type early on, if needed. */
if (g_enmDisplayServerType == VBGHDISPLAYSERVERTYPE_AUTO)
{
diff --git a/src/VBox/Frontends/VirtualBox/Makefile.kmk b/src/VBox/Frontends/VirtualBox/Makefile.kmk
index fe063f6f314..e1c1a7dd239 100644
--- a/src/VBox/Frontends/VirtualBox/Makefile.kmk
+++ b/src/VBox/Frontends/VirtualBox/Makefile.kmk
@@ -1150,7 +1150,6 @@ endif
# Common Guest / Host sources.
VBOX_GH_SOURCES := \
- $(PATH_ROOT)/src/VBox/GuestHost/Log.cpp \
$(PATH_ROOT)/src/VBox/GuestHost/DisplayServerType.cpp
#
diff --git a/src/VBox/GuestHost/DisplayServerType.cpp b/src/VBox/GuestHost/DisplayServerType.cpp
index 296e9d51d03..ee9a3f4b4ac 100644
--- a/src/VBox/GuestHost/DisplayServerType.cpp
+++ b/src/VBox/GuestHost/DisplayServerType.cpp
@@ -33,8 +33,8 @@
#include <iprt/env.h>
#include <iprt/string.h>
#include <iprt/ldr.h>
+#include <iprt/log.h>
-#include <VBox/GuestHost/Log.h>
#include <VBox/GuestHost/DisplayServerType.h>
@@ -101,7 +101,7 @@ static int vbghDisplayServerTryLoadLib(const char **apszLibs, size_t cLibs, PRTL
*/
VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
{
- VBGHLogVerbose(1, "Detecting display server ...\n");
+ LogRel2(("Detecting display server ...\n"));
/* Try to connect to the wayland display, assuming it succeeds only when a wayland compositor is active: */
bool fHasWayland = false;
@@ -179,7 +179,7 @@ VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
else if (fHasX)
retSessionType = VBGHDISPLAYSERVERTYPE_X11;
- VBGHLogVerbose(1, "Detected via connection: %s\n", VBGHDisplayServerTypeToStr(retSessionType));
+ LogRel2(("Detected via connection: %s\n", VBGHDisplayServerTypeToStr(retSessionType)));
/* If retSessionType is set, we assume we're done here;
* otherwise try the environment variables as a fallback. */
@@ -196,7 +196,7 @@ VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
if (pWaylandDisplayType != NULL)
waylandDisplayType = VBGHDISPLAYSERVERTYPE_WAYLAND;
- VBGHLogVerbose(1, "Wayland display type is: %s\n", VBGHDisplayServerTypeToStr(waylandDisplayType));
+ LogRel2(("Wayland display type is: %s\n", VBGHDisplayServerTypeToStr(waylandDisplayType)));
VBGHDISPLAYSERVERTYPE xdgSessionType = VBGHDISPLAYSERVERTYPE_NONE;
const char *pSessionType = RTEnvGet(VBGH_ENV_XDG_SESSION_TYPE);
@@ -208,7 +208,7 @@ VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
xdgSessionType = VBGHDISPLAYSERVERTYPE_X11;
}
- VBGHLogVerbose(1, "XDG session type is: %s\n", VBGHDisplayServerTypeToStr(xdgSessionType));
+ LogRel2(("XDG session type is: %s\n", VBGHDisplayServerTypeToStr(xdgSessionType)));
VBGHDISPLAYSERVERTYPE xdgCurrentDesktopType = VBGHDISPLAYSERVERTYPE_NONE;
@@ -221,7 +221,7 @@ VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
xdgCurrentDesktopType = VBGHDISPLAYSERVERTYPE_X11;
}
- VBGHLogVerbose(1, "XDG current desktop type is: %s\n", VBGHDisplayServerTypeToStr(xdgCurrentDesktopType));
+ LogRel2(("XDG current desktop type is: %s\n", VBGHDisplayServerTypeToStr(xdgCurrentDesktopType)));
/* Set the returning type according to the precedence. */
if (waylandDisplayType != VBGHDISPLAYSERVERTYPE_NONE) retSessionType = waylandDisplayType;
@@ -236,10 +236,10 @@ VBGHDISPLAYSERVERTYPE VBGHDisplayServerTypeDetect(void)
&& (a_Type2 != VBGHDISPLAYSERVERTYPE_NONE) \
&& (a_Type1 != a_Type2)) \
{ \
- VBGHLogError("Unable to reliably detect desktop environment:\n"); \
- VBGHLogError("Mismatch between %s (%s) and %s (%s) detected! This might indicate a misconfigured and/or broken system!\n", \
- #a_Type1, VBGHDisplayServerTypeToStr(a_Type1), #a_Type2, VBGHDisplayServerTypeToStr(a_Type2)); \
- VBGHLogError("Use --session-type to override this detection.\n"); \
+ LogRel(("Unable to reliably detect desktop environment:\n")); \
+ LogRel(("Mismatch between %s (%s) and %s (%s) detected! This might indicate a misconfigured and/or broken system!\n", \
+ #a_Type1, VBGHDisplayServerTypeToStr(a_Type1), #a_Type2, VBGHDisplayServerTypeToStr(a_Type2))); \
+ LogRel(("Use --session-type to override this detection.\n")); \
retSessionType = VBGHDISPLAYSERVERTYPE_NONE; \
}
diff --git a/src/VBox/GuestHost/Log.cpp b/src/VBox/GuestHost/Log.cpp
deleted file mode 100644
index 7b70b52adf4..00000000000
--- a/src/VBox/GuestHost/Log.cpp
+++ /dev/null
@@ -1,245 +0,0 @@
-/* $Id$ */
-/** @file
- * Guest / Host common code - Logging stubs. Might be overriden by a component to fit its needs.
- */
-
-/*
- * Copyright (C) 2023 Oracle and/or its affiliates.
- *
- * This file is part of VirtualBox base platform packages, as
- * available from https://www.virtualbox.org.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, in version 3 of the
- * License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <https://www.gnu.org/licenses>.
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-
-/*********************************************************************************************************************************
-* Header Files *
-*********************************************************************************************************************************/
-#include <iprt/string.h>
-
-#include <VBox/log.h>
-#include <VBox/GuestHost/Log.h>
-
-
-/*********************************************************************************************************************************
-* Globals *
-*********************************************************************************************************************************/
-static unsigned g_vbghLogVerbosity = 0; /* Current guest/host log verbosity level. */
-
-
-/*********************************************************************************************************************************
-* Implementation *
-*********************************************************************************************************************************/
-
-/**
- * Logs a message with a given prefix, format string and a va_list.
- *
- * @param pszPrefix Log prefix to use.
- * @param pszFormat Format string to use.
- * @param va va_list to use.
- */
-static void vbghLogV(const char *pszPrefix, const char *pszFormat, va_list va)
-{
- char *psz = NULL;
- RTStrAPrintfV(&psz, pszFormat, va);
- AssertPtrReturnVoid(psz);
- LogRel(("%s%s", pszPrefix ? pszPrefix : "", psz));
- RTStrFree(psz);
-}
-
-/** Logs a message with a prefix + a format string and va_list,
- * and executes a given statement afterwards. */
-#define VBGH_LOG_VALIST_STMT(a_Prefix, a_Fmt, a_VaList, a_Stmt) \
- { \
- vbghLogV(a_Prefix, a_Fmt, a_VaList); \
- a_Stmt; \
- }
-
-/** Logs a message with a prefix + a format string and va_list . */
-#define VBGH_LOG_VALIST(a_Prefix, a_Fmt, a_VaList) \
- VBGH_LOG_VALIST_STMT(a_Prefix, a_Fmt, a_VaList, do { } while (0))
-
-/** Logs a message with a prefix, a format string (plus variable arguments),
- * and executes a given statement afterwards. */
-#define VBGH_LOG_VA_STMT(a_Prefix, a_Fmt, a_Stmt) \
- { \
- va_list va; \
- va_start(va, a_Fmt); \
- VBGH_LOG_VALIST_STMT(a_Prefix, a_Fmt, va, a_Stmt); \
- va_end(va); \
- }
-
-/** Logs a message with a prefix + a format string (plus variable arguments). */
-#define VBGH_LOG_VA(a_Prefix, a_Fmt) \
- VBGH_LOG_VA_STMT(a_Prefix, a_Fmt, do { } while (0))
-
-/**
- * Shows a notification on the desktop (if available).
- *
- * @returns VBox status code.
- * @returns VERR_NOT_SUPPORTED if the current desktop environment is not supported.
- * @param pszHeader Header text to show.
- * @param pszBody Body text to show.
- *
- * @note Most notification implementations have length limits on their header / body texts, so keep
- * the text(s) short.
- */
-static int vbghShowNotifyV(const char *pszHeader, const char *pszFormat, va_list va)
-{
- vbghLogV(pszHeader, pszFormat, va);
-
- return VINF_SUCCESS;
-}
-
-/**
- * Shows a notification on the desktop (if available).
- *
- * @returns VBox status code.
- * @returns VERR_NOT_SUPPORTED if the current desktop environment is not supported.
- * @param pszHeader Header text to show.
- * @param pszFormat Format string of body text to show.
- *
- * @note Most notification implementations have length limits on their header / body texts, so keep
- * the text(s) short.
- */
-int VBGHShowNotify(const char *pszHeader, const char *pszFormat, ...)
-{
- va_list va;
- va_start(va, pszFormat);
- int rc = vbghShowNotifyV(pszHeader, pszFormat, va);
- va_end(va);
-
- return rc;
-}
-
-/**
- * Logs an error message with a va_list.
- *
- * @param pszFormat Format string..
- * @param va Format arguments.
- */
-void VBGHLogErrorV(const char *pszFormat, va_list va)
-{
- VBGH_LOG_VALIST("Error: ", pszFormat, va);
-}
-
-/**
- * Logs an error message to the (release) logging instance.
- *
- * @param pszFormat Format string to log.
- */
-void VBGHLogError(const char *pszFormat, ...)
-{
- VBGH_LOG_VA("Error: ", pszFormat);
-}
-
-/**
- * Logs a info message with a va_list.
- *
- * @param pszFormat Format string..
- * @param va Format arguments.
- */
-void VBGHLogInfoV(const char *pszFormat, va_list va)
-{
- VBGH_LOG_VALIST("", pszFormat, va);
-}
-
-/**
- * Logs an info message to the (release) logging instance.
- *
- * @param pszFormat Format string.
- */
-void VBGHLogInfo(const char *pszFormat, ...)
-{
- VBGH_LOG_VA("", pszFormat);
-}
-
-/**
- * Logs a fatal error, notifies the desktop environment via a message (if available).
- *
- * @param pszFormat Format string..
- * @param va Format arguments.
- */
-void VBGHLogFatalErrorV(const char *pszFormat, va_list va)
-{
- VBGH_LOG_VALIST_STMT("Fatal Error: ", pszFormat, va,
- (vbghShowNotifyV("Fatal Error: ", pszFormat, va)));
-}
-
-/**
- * Logs a fatal error, notifies the desktop environment via a message (if available).
- *
- * @param pszFormat Format string.
- * @param ... Variable arguments for format string. Optional.
- */
-void VBGHLogFatalError(const char *pszFormat, ...)
-{
- VBGH_LOG_VA_STMT("Fatal Error: ", pszFormat,
- vbghShowNotifyV("Fatal Error: ", pszFormat, va));
-}
-
-/**
- * Displays a verbose message based on the currently
- * set global verbosity level.
- *
- * @param iLevel Minimum log level required to display this message.
- * @param pszFormat Format string.
- * @param ... Format arguments.
- */
-void VBGHLogVerbose(unsigned iLevel, const char *pszFormat, ...)
-{
- if (iLevel <= g_vbghLogVerbosity)
- VBGH_LOG_VA("", pszFormat);
-}
-
-/**
- * Displays a verbose message based on the currently
- * set global verbosity level with a va_list.
- *
- * @param iLevel Minimum log level required to display this message.
- * @param pszFormat Format string.
- * @param va Format arguments.
- */
-void VBGHLogVerboseV(unsigned iLevel, const char *pszFormat, va_list va)
-{
- if (iLevel <= g_vbghLogVerbosity)
- VBGH_LOG_VALIST("", pszFormat, va);
-}
-
-/**
- * Sets the verbosity level.
- * @param iLevel Verbosity level to set.
- *
- * @note Not thread safe.
- */
-void VBGHLogVerbositySet(unsigned iLevel)
-{
- g_vbghLogVerbosity = iLevel;
-}
-
-/**
- * Gets the current verbosity level.
- *
- * @returns The current verbosity level.
- *
- * @note Not thread safe.
- */
-unsigned VBGHLogVerbosityGet(void)
-{
- return g_vbghLogVerbosity;
-}
-