VirtualBox

Ignore:
Timestamp:
Oct 9, 2017 11:52:45 AM (7 years ago)
Author:
vboxsync
Message:

Added RTERRINFO_LOG_* macros for logging RTErrInfo setings to the right group.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/err/errinfolog.cpp

    r68980 r69011  
    3434#include <iprt/assert.h>
    3535#include <iprt/string.h>
     36#include <iprt/log.h>
    3637
    3738
    38 RTDECL(int) RTErrInfoSet(PRTERRINFO pErrInfo, int rc, const char *pszMsg)
     39RTDECL(int) RTErrInfoLogAndSet(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg)
    3940{
     41    /* The logging: */
     42    if (fFlags & RTERRINFO_LOG_F_RELEASE)
     43    {
     44        PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     45        if (pLogger)
     46            RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %s\n", rc, pszMsg);
     47    }
     48
     49    PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     50    if (pLogger)
     51        RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %s\n", rc, pszMsg);
     52
     53    /* The setting: */
    4054    if (pErrInfo)
    4155    {
     
    5165
    5266
    53 RTDECL(int) RTErrInfoSetF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...)
     67RTDECL(int) RTErrInfoLogAndSetF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...)
    5468{
    5569    va_list va;
    5670    va_start(va, pszFormat);
    57     RTErrInfoSetV(pErrInfo, rc, pszFormat, va);
     71    RTErrInfoLogAndSetV(pErrInfo, rc, iLogGroup, fFlags, pszFormat, va);
    5872    va_end(va);
    5973    return rc;
     
    6175
    6276
    63 RTDECL(int) RTErrInfoSetV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va)
     77RTDECL(int) RTErrInfoLogAndSetV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va)
    6478{
     79    /* The logging: */
     80    if (fFlags & RTERRINFO_LOG_F_RELEASE)
     81    {
     82        PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     83        if (pLogger)
     84            RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %N\n", rc, pszFormat, &va);
     85    }
     86
     87    PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     88    if (pLogger)
     89        RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %N\n", rc, pszFormat, &va);
     90
     91    /* The setting: */
    6592    if (pErrInfo)
    6693    {
     
    76103
    77104
    78 RTDECL(int) RTErrInfoAdd(PRTERRINFO pErrInfo, int rc, const char *pszMsg)
     105RTDECL(int) RTErrInfoLogAndAdd(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg)
    79106{
    80107    if (pErrInfo)
     
    90117        }
    91118    }
     119
     120    /* The logging: */
     121    if (fFlags & RTERRINFO_LOG_F_RELEASE)
     122    {
     123        PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     124        if (pLogger)
     125            RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %s\n", rc, pszMsg);
     126    }
     127
     128    PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     129    if (pLogger)
     130        RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %s\n", rc, pszMsg);
     131
    92132    return rc;
    93133}
    94134
    95135
    96 RTDECL(int) RTErrInfoAddF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...)
     136RTDECL(int) RTErrInfoLogAndAddF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...)
    97137{
    98138    va_list va;
    99139    va_start(va, pszFormat);
    100     RTErrInfoAddV(pErrInfo, rc, pszFormat, va);
     140    RTErrInfoLogAndAddV(pErrInfo, rc, iLogGroup, fFlags, pszFormat, va);
    101141    va_end(va);
    102142    return rc;
     
    104144
    105145
    106 RTDECL(int) RTErrInfoAddV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va)
     146RTDECL(int) RTErrInfoLogAndAddV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va)
    107147{
    108148    if (pErrInfo)
     
    114154            char *pszOut = (char *)memchr(pErrInfo->pszMsg, '\0', pErrInfo->cbMsg - 2);
    115155            if (pszOut)
    116                 RTStrPrintfV(pszOut, &pErrInfo->pszMsg[pErrInfo->cbMsg] - pszOut, pszFormat, va);
     156            {
     157                va_list va2;
     158                va_copy(va2, va);
     159                RTStrPrintfV(pszOut, &pErrInfo->pszMsg[pErrInfo->cbMsg] - pszOut, pszFormat, va2);
     160                va_end(va2);
     161            }
    117162        }
    118163        else
     
    123168        }
    124169    }
     170
     171    /* The logging: */
     172    if (fFlags & RTERRINFO_LOG_F_RELEASE)
     173    {
     174        PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     175        if (pLogger)
     176            RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %N\n", rc, pszFormat, &va);
     177    }
     178
     179    PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
     180    if (pLogger)
     181        RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %N\n", rc, pszFormat, &va);
     182
    125183    return rc;
    126184}
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