VirtualBox

Ignore:
Timestamp:
May 9, 2023 8:28:38 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157237
Message:

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

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk

    r99620 r99689  
    5151# Common Guest / Host sources.
    5252VBOX_GH_SOURCES := \
    53         $(PATH_ROOT)/src/VBox/GuestHost/Log.cpp \
    5453        $(PATH_ROOT)/src/VBox/GuestHost/DisplayServerType.cpp
    5554
  • trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h

    r99658 r99689  
    3737#include <iprt/string.h>
    3838
    39 #include <VBox/GuestHost/Log.h>
    4039#include <VBox/GuestHost/DisplayServerType.h>
    4140
     
    4948int VBClLogCreate(const char *pszLogFile);
    5049int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader);
     50int VBClLogModify(const char *pszDest, unsigned uVerbosity);
    5151void VBClLogSetLogPrefix(const char *pszPrefix);
    5252void VBClLogDestroy(void);
  • trunk/src/VBox/Additions/x11/VBoxClient/logging.cpp

    r99658 r99689  
    4141#endif
    4242#include <VBox/VBoxGuestLib.h>
    43 
    44 #include <VBox/GuestHost/Log.h>
    4543
    4644#include <package-generated.h>
     
    223221
    224222/**
     223 * Logs a message with a given prefix, format string and a va_list.
     224 *
     225 * @param   pszPrefix           Log prefix to use.
     226 * @param   pszFormat           Format string to use.
     227 * @param   va                  va_list to use.
     228 */
     229static void vbclLogV(const char *pszPrefix, const char *pszFormat, va_list va)
     230{
     231    char *psz = NULL;
     232    RTStrAPrintfV(&psz, pszFormat, va);
     233    AssertPtrReturnVoid(psz);
     234    LogRel(("%s%s", pszPrefix ? pszPrefix : "", psz));
     235    RTStrFree(psz);
     236}
     237
     238/**
    225239 * Logs a fatal error, notifies the desktop environment via a message and
    226240 * exits the application immediately.
     
    233247    va_list va;
    234248    va_start(va, pszFormat);
    235     VBGHLogFatalErrorV(pszFormat, va);
     249    vbclLogV("Fatal Error: ", pszFormat, va);
    236250    va_end(va);
    237251}
     
    246260    va_list va;
    247261    va_start(va, pszFormat);
    248     VBGHLogErrorV(pszFormat, va);
     262    vbclLogV("Error: ", pszFormat, va);
    249263    va_end(va);
    250264}
     
    259273    va_list va;
    260274    va_start(va, pszFormat);
    261     VBGHLogInfoV(pszFormat, va);
     275    vbclLogV("", pszFormat, va);
    262276    va_end(va);
    263277}
     
    275289    va_list va;
    276290    va_start(va, pszFormat);
    277     VBGHLogVerboseV(iLevel, pszFormat, va);
     291    if (iLevel <= g_cVerbosity)
     292        vbclLogV("", pszFormat, va);
    278293    va_end(va);
    279294}
     
    419434
    420435/**
     436 * Destroys the currently active logging instance.
     437 */
     438void VBClLogDestroy(void)
     439{
     440    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
     441}
     442
     443/**
     444 * Modifies the (release) log settings.
     445 *
     446 * @returns VBox status code.
     447 * @param   pszDest             Log destination string to set.
     448 * @param   uVerbosity          Verbosity level to set.
     449 *
     450 * @note    Errors will be logged to stderr.
     451 */
     452int VBClLogModify(const char *pszDest, unsigned uVerbosity)
     453{
     454    AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
     455    AssertPtrReturn(g_pLoggerRelease, VERR_INVALID_POINTER);
     456
     457    int rc = RTLogDestinations(g_pLoggerRelease, pszDest);
     458    if (RT_SUCCESS(rc))
     459    {
     460#define LOG_GROUP_SET_BREAK(a_Val) \
     461        rc = RTLogGroupSettings(g_pLoggerRelease, "all.e" a_Val); break;
     462
     463        switch (uVerbosity)
     464        {
     465            case 0:  LOG_GROUP_SET_BREAK("");
     466            case 1:  LOG_GROUP_SET_BREAK(".l");
     467            case 2:  LOG_GROUP_SET_BREAK(".l.l2");
     468            case 3:  LOG_GROUP_SET_BREAK(".l.l2.l3");
     469            default: LOG_GROUP_SET_BREAK(".l.l2.l3.l4");
     470        }
     471#undef LOG_GROUP_SET_BREAK
     472    }
     473
     474    if (RT_FAILURE(rc)) /* Print to stderr in the hope that anyone can read this. */
     475        RTMsgError("Failed to set/modify log output, rc=%Rrc", rc);
     476
     477    return rc;
     478}
     479
     480/**
    421481 * Set custom log prefix.
    422482 *
     
    428488}
    429489
    430 /**
    431  * Destroys the currently active logging instance.
    432  */
    433 void VBClLogDestroy(void)
    434 {
    435     RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
    436 }
    437 
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r99660 r99689  
    674674                if (RT_SUCCESS(rc))
    675675                {
    676                     VBGHLogVerbositySet(2);
    677                     VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect();
    678                     VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType));
    679                     return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     676                    /* Make sure that we increase the verbosity (if needed), to gain some more insights
     677                     * when detecting the display server. */
     678                    rc = VBClLogModify("stdout", g_cVerbosity);
     679                    if (RT_SUCCESS(rc))
     680                    {
     681                        VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect();
     682                        VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType));
     683                        return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     684                    }
    680685                }
    681686
     
    740745        return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogCreateEx(). */
    741746
    742     if (!fDaemonise)
    743     {
    744         /* If the user is running in "no daemon" mode, send critical logging to stdout as well. */
    745         PRTLOGGER pReleaseLog = RTLogRelGetDefaultInstance();
    746         if (pReleaseLog)
    747         {
    748             rc = RTLogDestinations(pReleaseLog, "stdout");
    749             if (RT_FAILURE(rc))
    750                 return RTMsgErrorExitFailure("Failed to redivert error output, rc=%Rrc", rc);
    751         }
    752     }
     747    /* If the user is running in "no daemon" mode, send critical logging to stdout as well. */
     748    rc = VBClLogModify(fDaemonise ? "" : "stdout", g_cVerbosity);
     749    if (RT_FAILURE(rc))
     750        return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogModify(). */
    753751
    754752    VBClLogInfo("VBoxClient %s r%s started. Verbose level = %d\n",
    755753                RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity);
    756 
    757     VBGHLogVerbositySet(g_cVerbosity);
    758754
    759755    /* Try to detect the current session type early on, if needed. */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette