VirtualBox

Changeset 93220 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 13, 2022 11:45:40 AM (3 years ago)
Author:
vboxsync
Message:

Additions: X11: add interface to set custom log prefix, bugref:10134.

Each VBoxClient service instance now can use separate logging prefix,
so it can be easier to look at the log on a host side.

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

Legend:

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

    r93115 r93220  
    3333
    3434int VBClLogCreate(const char *pszLogFile);
     35void VBClLogSetLogPrefix(const char *pszPrefix);
    3536void VBClLogDestroy(void);
    3637
     
    107108extern VBCLSERVICE g_SvcDisplayDRM;
    108109extern VBCLSERVICE g_SvcDisplaySVGA;
     110extern VBCLSERVICE g_SvcDisplaySVGASession;
    109111extern VBCLSERVICE g_SvcDragAndDrop;
    110112extern VBCLSERVICE g_SvcHostVersion;
  • trunk/src/VBox/Additions/x11/VBoxClient/logging.cpp

    r93115 r93220  
    3434static uint32_t      g_uHistoryFileTime = RT_SEC_1DAY;  /* Max 1 day per file. */
    3535static uint64_t      g_uHistoryFileSize = 100 * _1M;    /* Max 100MB per file. */
     36
     37/** Custom log prefix (to be set externally). */
     38static char          *g_pszCustomLogPrefix;
    3639
    3740extern unsigned      g_cRespawn;
     
    244247}
    245248
     249static DECLCALLBACK(size_t) vbClLogPrefixCb(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
     250{
     251    size_t cbPrefix = 0;
     252
     253    RT_NOREF(pLogger);
     254    RT_NOREF(pvUser);
     255
     256    if (g_pszCustomLogPrefix)
     257    {
     258        cbPrefix = RT_MIN(strlen(g_pszCustomLogPrefix), cchBuf);
     259        memcpy(pchBuf, g_pszCustomLogPrefix, cbPrefix);
     260    }
     261
     262    return cbPrefix;
     263}
     264
    246265/**
    247266 * Creates the default release logger outputting to the specified file.
     
    259278    /* Create release logger (stdout + file). */
    260279    static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
    261     RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME;
     280    RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME | RTLOGFLAGS_PREFIX_CUSTOM;
    262281#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    263282    fFlags |= RTLOGFLAGS_USECRLF;
     
    273292        RTLogRelSetDefaultInstance(g_pLoggerRelease);
    274293
     294        rc = RTLogSetCustomPrefixCallback(g_pLoggerRelease, vbClLogPrefixCb, NULL);
     295        if (RT_FAILURE(rc))
     296            VBClLogError("unable to register custom log prefix callback\n");
     297
    275298        /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */
    276299        RTLogFlush(g_pLoggerRelease);
     
    281304
    282305/**
     306 * Set custom log prefix.
     307 *
     308 * @param pszPrefix     Custom log prefix string.
     309 */
     310void VBClLogSetLogPrefix(const char *pszPrefix)
     311{
     312    g_pszCustomLogPrefix = (char *)pszPrefix;
     313}
     314
     315/**
    283316 * Destroys the currently active logging instance.
    284317 */
Note: See TracChangeset for help on using the changeset viewer.

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