VirtualBox

Changeset 3086

Show
Ignore:
Timestamp:
06/11/07 10:43:47 (2 years ago)
Author:
vboxsync
Message:

introduced RTLogCreateEx and RTLogCreateExV to be able to pass an error string back to the caller

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/iprt/log.h

    r2981 r3086  
    10871087 
    10881088/** 
     1089 * Create a logger instance. 
     1090 * 
     1091 * @returns iprt status code. 
     1092 * 
     1093 * @param   ppLogger            Where to store the logger instance. 
     1094 * @param   fFlags              Logger instance flags, a combination of the RTLOGFLAGS_* values. 
     1095 * @param   pszGroupSettings    The initial group settings. 
     1096 * @param   pszEnvVarBase       Base name for the environment variables for this instance. 
     1097 * @param   cGroups             Number of groups in the array. 
     1098 * @param   papszGroups         Pointer to array of groups. This must stick around for the life of the 
     1099 *                              logger instance. 
     1100 * @param   fDestFlags          The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified. 
     1101 * @param   pszErrorMsg         A buffer which is filled with an error message if something fails. May be NULL. 
     1102 * @param   cchErrorMsg         The size of the error message buffer. 
     1103 * @param   pszFilenameFmt      Log filename format string. Standard RTStrFormat(). 
     1104 * @param   ...                 Format arguments. 
     1105 */ 
     1106RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
     1107                          const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
     1108                          RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...); 
     1109 
     1110/** 
     1111 * Create a logger instance. 
     1112 * 
     1113 * @returns iprt status code. 
     1114 * 
     1115 * @param   ppLogger            Where to store the logger instance. 
     1116 * @param   fFlags              Logger instance flags, a combination of the RTLOGFLAGS_* values. 
     1117 * @param   pszGroupSettings    The initial group settings. 
     1118 * @param   pszEnvVarBase       Base name for the environment variables for this instance. 
     1119 * @param   cGroups             Number of groups in the array. 
     1120 * @param   papszGroups         Pointer to array of groups. This must stick around for the life of the 
     1121 *                              logger instance. 
     1122 * @param   fDestFlags          The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified. 
     1123 * @param   pszErrorMsg         A buffer which is filled with an error message if something fails. May be NULL. 
     1124 * @param   cchErrorMsg         The size of the error message buffer. 
     1125 * @param   pszFilenameFmt      Log filename format string. Standard RTStrFormat(). 
     1126 * @param   args                Format arguments. 
     1127 */ 
     1128RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
     1129                           const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
     1130                           RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args); 
     1131 
     1132/** 
    10891133 * Create a logger instance for singled threaded ring-0 usage. 
    10901134 * 
  • trunk/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp

    r2981 r3086  
    935935    { 
    936936        static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; 
     937        static char szError[RTPATH_MAX + 128] = ""; 
    937938        PRTLOGGER pLogger; 
    938         rc2 = RTLogCreate(&pLogger, RTLOGFLAGS_PREFIX_TIME_PROG, "all", 
    939                           "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups, 
    940                           RTLOGDEST_FILE, "./VBoxBFE.log"); 
     939        rc2 = RTLogCreateEx(&pLogger, RTLOGFLAGS_PREFIX_TIME_PROG, "all", 
     940                            "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups, 
     941                            RTLOGDEST_FILE, szError, sizeof(szError), "./VBoxBFE.log"); 
    941942        if (VBOX_SUCCESS(rc2)) 
    942943        { 
     
    954955            RTLogRelSetDefaultInstance(pLogger); 
    955956        } 
     957        else 
     958            RTPrintf("Could not open release log (%s)\n", szError); 
    956959    } 
    957960 
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r3045 r3086  
    65556555        fFlags |= RTLOGFLAGS_USECRLF; 
    65566556#endif /* __WIN__ */ 
    6557         vrc = RTLogCreate(&loggerRelease, fFlags, "all", 
    6558                           "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups, 
    6559                           RTLOGDEST_FILE, logFile.raw()); 
     6557        char szError[RTPATH_MAX + 128] = ""; 
     6558        vrc = RTLogCreateEx(&loggerRelease, fFlags, "all", 
     6559                            "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups, 
     6560                            RTLOGDEST_FILE, szError, sizeof(szError), logFile.raw()); 
    65606561        if (VBOX_SUCCESS(vrc)) 
    65616562        { 
     
    65766577        { 
    65776578            hrc = setError (E_FAIL, 
    6578                 tr ("Failed to open release log file '%s' (%Vrc)"), 
    6579                 logFile.raw(), vrc); 
     6579                tr ("Failed to open release log (%s, %Vrc)"), szError, vrc); 
    65806580            break; 
    65816581        } 
  • trunk/src/VBox/Runtime/log.cpp

    r2981 r3086  
    165165#ifndef IN_GC 
    166166/** 
    167  * Create a logger instance
     167 * Create a logger instance, comprehensive version
    168168 * 
    169169 * @returns iprt status code. 
     
    177177 *                              logger instance. 
    178178 * @param   fDestFlags          The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified. 
     179 * @param   pszErrorMsg         A buffer which is filled with an error message if something fails. May be NULL. 
     180 * @param   cchErrorMsg         The size of the error message buffer. 
    179181 * @param   pszFilenameFmt      Log filename format string. Standard RTStrFormat(). 
    180182 * @param   ...                 Format arguments. 
    181183 */ 
    182 RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
    183                         const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
    184                         RTUINT fDestFlags, const char *pszFilenameFmt, ...
     184RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
     185                           const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
     186                           RTUINT fDestFlags, char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args
    185187{ 
    186188    /* 
     
    250252            if (pszFilenameFmt) 
    251253            { 
    252                 va_list args; 
    253                 va_start(args, pszFilenameFmt); 
    254254                RTStrPrintfV(pLogger->pszFilename, RTPATH_MAX, pszFilenameFmt, args); 
    255                 va_end(args); 
    256255                pLogger->fDestFlags |= RTLOGDEST_FILE; 
    257256            } 
     
    398397#ifdef IN_RING3 
    399398            if (pLogger->fDestFlags & RTLOGDEST_FILE) 
     399            { 
    400400                rc = RTFileOpen(&pLogger->File, pLogger->pszFilename, 
    401401                                RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE); 
     402                if (RT_FAILURE(rc)) 
     403                    RTStrPrintf(pszErrorMsg, cchErrorMsg, "could not open file '%s'", pLogger->pszFilename); 
     404            } 
    402405#endif  /* IN_RING3 */ 
    403406 
     
    413416                    return VINF_SUCCESS; 
    414417                } 
     418                else 
     419                    RTStrPrintf(pszErrorMsg, cchErrorMsg, "failed to create sempahore"); 
    415420            } 
    416421#ifdef IN_RING3 
     
    429434} 
    430435 
     436/** 
     437 * Create a logger instance. 
     438 * 
     439 * @returns iprt status code. 
     440 * 
     441 * @param   ppLogger            Where to store the logger instance. 
     442 * @param   fFlags              Logger instance flags, a combination of the RTLOGFLAGS_* values. 
     443 * @param   pszGroupSettings    The initial group settings. 
     444 * @param   pszEnvVarBase       Base name for the environment variables for this instance. 
     445 * @param   cGroups             Number of groups in the array. 
     446 * @param   papszGroups         Pointer to array of groups. This must stick around for the life of the 
     447 *                              logger instance. 
     448 * @param   fDestFlags          The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified. 
     449 * @param   pszFilenameFmt      Log filename format string. Standard RTStrFormat(). 
     450 * @param   ...                 Format arguments. 
     451 */ 
     452RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
     453                        const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
     454                        RTUINT fDestFlags, const char *pszFilenameFmt, ...) 
     455{ 
     456    va_list args; 
     457    int rc; 
     458 
     459    va_start(args, pszFilenameFmt); 
     460    rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, fDestFlags, NULL, 0, pszFilenameFmt, args); 
     461    va_end(args); 
     462    return rc; 
     463} 
     464 
     465/** 
     466 * Create a logger instance. 
     467 * 
     468 * @returns iprt status code. 
     469 * 
     470 * @param   ppLogger            Where to store the logger instance. 
     471 * @param   fFlags              Logger instance flags, a combination of the RTLOGFLAGS_* values. 
     472 * @param   pszGroupSettings    The initial group settings. 
     473 * @param   pszEnvVarBase       Base name for the environment variables for this instance. 
     474 * @param   cGroups             Number of groups in the array. 
     475 * @param   papszGroups         Pointer to array of groups. This must stick around for the life of the 
     476 *                              logger instance. 
     477 * @param   fDestFlags          The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified. 
     478 * @param   pszErrorMsg         A buffer which is filled with an error message if something fails. May be NULL. 
     479 * @param   cchErrorMsg         The size of the error message buffer. 
     480 * @param   pszFilenameFmt      Log filename format string. Standard RTStrFormat(). 
     481 * @param   ...                 Format arguments. 
     482 */ 
     483RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, RTUINT fFlags, const char *pszGroupSettings, 
     484                          const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 
     485                          RTUINT fDestFlags,  char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...) 
     486{ 
     487    va_list args; 
     488    int rc; 
     489 
     490    va_start(args, pszFilenameFmt); 
     491    rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, fDestFlags, pszErrorMsg, cchErrorMsg, pszFilenameFmt, args); 
     492    va_end(args); 
     493    return rc; 
     494} 
    431495 
    432496/** 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy