VirtualBox

Changeset 20853 in vbox for trunk


Ignore:
Timestamp:
Jun 23, 2009 4:31:12 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48996
Message:

IPRT: Added custom prefix callback to the logger.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/log.h

    r20835 r20853  
    183183 */
    184184typedef DECLCALLBACK(void) FNRTLOGFLUSH(PRTLOGGER pLogger);
    185 /** Pointer to logger function. */
     185/** Pointer to flush function. */
    186186typedef FNRTLOGFLUSH *PFNRTLOGFLUSH;
    187187
     
    194194/** Pointer to logger function. */
    195195typedef RCPTRTYPE(FNRTLOGFLUSHGC *) PFNRTLOGFLUSHGC;
     196
     197/**
     198 * Custom log prefix callback.
     199 *
     200 *
     201 * @returns The number of chars written.
     202 *
     203 * @param   pLogger     Pointer to the logger instance.
     204 * @param   pchBuf      Output buffer pointer.
     205 *                      No need to terminate the output.
     206 * @param   cchBuf      The size of the output buffer.
     207 * @param   pvUser      The user argument.
     208 */
     209typedef DECLCALLBACK(size_t) FNRTLOGPREFIX(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
     210/** Pointer to prefix callback function. */
     211typedef FNRTLOGPREFIX *PFNRTLOGPREFIX;
     212
    196213
    197214
     
    253270    /** Pointer to the flush function. */
    254271    PFNRTLOGFLUSH           pfnFlush;
     272    /** Custom prefix callback. */
     273    PFNRTLOGPREFIX          pfnPrefix;
     274    /** Prefix callback argument. */
     275    void                   *pvPrefixUserArg;
    255276    /** Mutex. */
    256277    RTSEMFASTMUTEX          MutexSem;
     
    283304#define RTLOGGER_MAGIC      0x19281207
    284305
    285 #endif
     306#endif /* !IN_RC */
    286307
    287308
     
    323344    /** New lines should be prefixed with thread name. */
    324345    RTLOGFLAGS_PREFIX_THREAD        = 0x00800000,
    325     /** New lines should be prefixed with the VCPU id. */
    326     RTLOGFLAGS_PREFIX_VCPU          = 0x01000000,
     346    /** New lines should be prefixed with data from a custom callback. */
     347    RTLOGFLAGS_PREFIX_CUSTOM        = 0x01000000,
    327348    /** New lines should be prefixed with formatted timestamp since program start. */
    328349    RTLOGFLAGS_PREFIX_TIME_PROG     = 0x04000000,
     
    14031424
    14041425/**
     1426 * Sets the custom prefix callback.
     1427 *
     1428 * @returns IPRT status code.
     1429 * @param   pLogger     The logger instance.
     1430 * @param   pfnCallback The callback.
     1431 * @param   pvUser      The user argument for the callback.
     1432 *  */
     1433RTDECL(int) RTLogSetCustomPrefixCallback(PRTLOGGER pLogger, PFNRTLOGPREFIX pfnCallback, void *pvUser);
     1434
     1435/**
    14051436 * Copies the group settings and flags from logger instance to another.
    14061437 *
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r20819 r20853  
    933933        rtlogUnlock(pDstLogger);
    934934    }
     935}
     936
     937
     938/**
     939 * Sets the custom prefix callback.
     940 *
     941 * @returns IPRT status code.
     942 * @param   pLogger     The logger instance.
     943 * @param   pfnCallback The callback.
     944 * @param   pvUser      The user argument for the callback.
     945 *  */
     946RTDECL(int) RTLogSetCustomPrefixCallback(PRTLOGGER pLogger, PFNRTLOGPREFIX pfnCallback, void *pvUser)
     947{
     948    /*
     949     * Resolve defaults.
     950     */
     951    if (!pLogger)
     952    {
     953        pLogger = RTLogDefaultInstance();
     954        if (!pLogger)
     955            return VINF_SUCCESS;
     956    }
     957    AssertReturn(pLogger->u32Magic == RTLOGGER_MAGIC, VERR_INVALID_MAGIC);
     958
     959    /*
     960     * Do the work.
     961     */
     962    rtlogLock(pLogger);
     963    pLogger->pvPrefixUserArg = pvUser;
     964    pLogger->pfnPrefix       = pfnCallback;
     965    rtlogUnlock(pLogger);
     966
     967    return VINF_SUCCESS;
    935968}
    936969
     
    12751308            { "tid",          sizeof("tid"         ) - 1,   RTLOGFLAGS_PREFIX_TID,          false },
    12761309            { "thread",       sizeof("thread"      ) - 1,   RTLOGFLAGS_PREFIX_THREAD,       false },
     1310            { "custom",       sizeof("custom"      ) - 1,   RTLOGFLAGS_PREFIX_CUSTOM,       false },
    12771311            { "timeprog",     sizeof("timeprog"    ) - 1,   RTLOGFLAGS_PREFIX_TIME_PROG,    false },
    12781312            { "time",         sizeof("time"        ) - 1,   RTLOGFLAGS_PREFIX_TIME,         false },
     
    19331967                /*
    19341968                 * Flush the buffer if there isn't enough room for the maximum prefix config.
    1935                  * Max is 224, add a couple of extra bytes.
     1969                 * Max is 256, add a couple of extra bytes.
    19361970                 */
    1937                 if (cb < 224 + 16)
     1971                if (cb < 256 + 16)
    19381972                {
    19391973                    rtlogFlush(pLogger);
     
    20842118                    const char *pszName = RTThreadSelfName();
    20852119#elif defined IN_RC
    2086                     const char *pszName = "EMT-GC";
     2120                    const char *pszName = "EMT-RC";
    20872121#else
    2088                     const char *pszName = "EMT-R0";
     2122                    const char *pszName = "R0";
    20892123#endif
    20902124                    size_t cch = 0;
     
    21102144                    *psz++ = ' ';                                                               /* +17 */
    21112145                }
     2146#ifndef IN_RC
     2147                if (    (pLogger->fFlags & RTLOGFLAGS_PREFIX_CUSTOM)
     2148                    &&  pLogger->pfnPrefix)
     2149                {
     2150                    psz += pLogger->pfnPrefix(pLogger, psz, 31, pLogger->pvPrefixUserArg);
     2151                    *psz++ = ' ';                                                               /* +32 */
     2152                }
     2153#endif
    21122154                if (pLogger->fFlags & RTLOGFLAGS_PREFIX_LOCK_COUNTS)
    21132155                {
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