- Timestamp:
- Apr 19, 2022 9:20:51 AM (3 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r93372 r94624 318 318 0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT | RTLOGDEST_USER, 319 319 vgsvcLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, 320 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 320 321 NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : ""); 321 322 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Additions/x11/VBoxClient/logging.cpp
r93220 r94624 286 286 0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT | RTLOGDEST_USER, 287 287 vbClLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, 288 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 288 289 NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : ""); 289 290 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Main/glue/VBoxLogRelCreate.cpp
r93115 r94624 172 172 cMaxEntriesPerGroup, 0 /*cBufDescs*/, NULL /*paBufDescs*/, fDestFlags, 173 173 vboxHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime, 174 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 174 175 pErrInfo, pcszLogFile ? "%s" : NULL, pcszLogFile); 175 176 if (RT_SUCCESS(vrc)) -
trunk/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestApp.cpp
r94138 r94624 303 303 0 /*cBufDescs*/, NULL /*paBufDescs*/, enmLogDest, 304 304 NULL /*pfnBeginEnd*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*uHistoryTimeMax*/, 305 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 305 306 NULL /*pErrInfo*/, pszFilenameFmt, pszFilename, RTTimeMilliTS()); 306 307 if (RT_SUCCESS(vrc)) -
trunk/src/VBox/Runtime/common/log/RTLogCreateEx.cpp
r93115 r94624 40 40 uint32_t cBufDescs, PRTLOGBUFFERDESC paBufDescs, uint32_t fDestFlags, 41 41 PFNRTLOGPHASE pfnPhase, uint32_t cHistory, uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot, 42 PCRTLOGOUTPUTIF pOutputIf, void *pvOutputIfUser, 42 43 PRTERRINFO pErrInfo, const char *pszFilenameFmt, ...) 43 44 { … … 49 50 cBufDescs, paBufDescs, fDestFlags, 50 51 pfnPhase, cHistory, cbHistoryFileMax, cSecsHistoryTimeSlot, 52 pOutputIf, pvOutputIfUser, 51 53 pErrInfo, pszFilenameFmt, va); 52 54 va_end(va); -
trunk/src/VBox/Runtime/common/log/log.cpp
r94611 r94624 212 212 * This can be NULL. */ 213 213 PFNRTLOGPHASE pfnPhase; 214 215 /** Handle to log file (if open). */ 214 /** Pointer to the output interface used. */ 215 PCRTLOGOUTPUTIF pOutputIf; 216 /** Opaque user data passed to the callbacks in the output interface. */ 217 void *pvOutputIfUser; 218 219 /** Handle to log file (if open) - only used by the default output interface to avoid additional layers of indirection. */ 216 220 RTFILE hFile; 217 221 /** Log file history settings: maximum amount of data to put in a file. */ … … 228 232 /** Pointer to filename. */ 229 233 char szFilename[RTPATH_MAX]; 234 /** Flag whether the log file was opened successfully. */ 235 bool fLogOpened; 230 236 /** @} */ 231 237 #endif /* IN_RING3 */ … … 241 247 242 248 /** The revision of the internal logger structure. */ 243 # define RTLOGGERINTERNAL_REV UINT32_C(1 2)249 # define RTLOGGERINTERNAL_REV UINT32_C(13) 244 250 245 251 AssertCompileMemberAlignment(RTLOGGERINTERNAL, cbRingBufUnflushed, sizeof(uint64_t)); … … 725 731 726 732 733 #ifdef IN_RING3 734 /********************************************************************************************************************************* 735 * Default file I/O interface * 736 *********************************************************************************************************************************/ 737 738 static DECLCALLBACK(int) rtLogOutputIfDefOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename, uint32_t fFlags) 739 { 740 RT_NOREF(pIf); 741 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvUser; 742 743 return RTFileOpen(&pLoggerInt->hFile, pszFilename, fFlags); 744 } 745 746 747 static DECLCALLBACK(int) rtLogOutputIfDefClose(PCRTLOGOUTPUTIF pIf, void *pvUser) 748 { 749 RT_NOREF(pIf); 750 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvUser; 751 752 int rc = VINF_SUCCESS; 753 if (pLoggerInt->hFile != NIL_RTFILE) 754 rc = RTFileClose(pLoggerInt->hFile); 755 756 pLoggerInt->hFile = NIL_RTFILE; 757 return rc; 758 } 759 760 761 static DECLCALLBACK(int) rtLogOutputIfDefDelete(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename) 762 { 763 RT_NOREF(pIf, pvUser); 764 return RTFileDelete(pszFilename); 765 } 766 767 768 static DECLCALLBACK(int) rtLogOutputIfDefRename(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilenameOld, 769 const char *pszFilenameNew, uint32_t fFlags) 770 { 771 RT_NOREF(pIf, pvUser); 772 return RTFileRename(pszFilenameOld, pszFilenameNew, fFlags); 773 } 774 775 776 static DECLCALLBACK(int) rtLogOutputIfDefQuerySize(PCRTLOGOUTPUTIF pIf, void *pvUser, uint64_t *pcbSize) 777 { 778 RT_NOREF(pIf); 779 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvUser; 780 781 if (pLoggerInt->hFile != NIL_RTFILE) 782 return RTFileQuerySize(pLoggerInt->hFile, pcbSize); 783 784 *pcbSize = 0; 785 return VINF_SUCCESS; 786 } 787 788 789 static DECLCALLBACK(int) rtLogOutputIfDefWrite(PCRTLOGOUTPUTIF pIf, void *pvUser, const void *pvBuf, 790 size_t cbWrite, size_t *pcbWritten) 791 { 792 RT_NOREF(pIf); 793 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvUser; 794 795 if (pLoggerInt->hFile != NIL_RTFILE) 796 return RTFileWrite(pLoggerInt->hFile, pvBuf, cbWrite, pcbWritten); 797 798 return VINF_SUCCESS; 799 } 800 801 802 static DECLCALLBACK(int) rtLogOutputIfDefFlush(PCRTLOGOUTPUTIF pIf, void *pvUser) 803 { 804 RT_NOREF(pIf); 805 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvUser; 806 807 if (pLoggerInt->hFile != NIL_RTFILE) 808 return RTFileFlush(pLoggerInt->hFile); 809 810 return VINF_SUCCESS; 811 } 812 813 814 /** 815 * The default file output interface. 816 */ 817 static const RTLOGOUTPUTIF g_LogOutputIfDef = 818 { 819 rtLogOutputIfDefOpen, 820 rtLogOutputIfDefClose, 821 rtLogOutputIfDefDelete, 822 rtLogOutputIfDefRename, 823 rtLogOutputIfDefQuerySize, 824 rtLogOutputIfDefWrite, 825 rtLogOutputIfDefFlush 826 }; 827 #endif 828 829 727 830 /********************************************************************************************************************************* 728 831 * Ring Buffer * … … 954 1057 if (pLoggerInt->fDestFlags & RTLOGDEST_FILE) 955 1058 { 956 if (pLoggerInt-> hFile != NIL_RTFILE)1059 if (pLoggerInt->fLogOpened) 957 1060 { 958 1061 if (cchPreamble) 959 RTFileWrite(pLoggerInt->hFile, pszPreamble, cchPreamble, NULL); 1062 pLoggerInt->pOutputIf->pfnWrite(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 1063 pszPreamble, cchPreamble, NULL /*pcbWritten*/); 960 1064 if (cchFirst) 961 RTFileWrite(pLoggerInt->hFile, pszFirst, cchFirst, NULL); 1065 pLoggerInt->pOutputIf->pfnWrite(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 1066 pszFirst, cchFirst, NULL /*pcbWritten*/); 962 1067 if (cchSecond) 963 RTFileWrite(pLoggerInt->hFile, pszSecond, cchSecond, NULL); 1068 pLoggerInt->pOutputIf->pfnWrite(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 1069 pszSecond, cchSecond, NULL /*pcbWritten*/); 964 1070 if (pLoggerInt->fFlags & RTLOGFLAGS_FLUSH) 965 RTFileFlush(pLoggerInt->hFile);1071 pLoggerInt->pOutputIf->pfnFlush(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser); 966 1072 } 967 1073 if (pLoggerInt->cHistory) … … 1012 1118 uint32_t cBufDescs, PRTLOGBUFFERDESC paBufDescs, uint32_t fDestFlags, 1013 1119 PFNRTLOGPHASE pfnPhase, uint32_t cHistory, uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot, 1120 PCRTLOGOUTPUTIF pOutputIf, void *pvOutputIfUser, 1014 1121 PRTERRINFO pErrInfo, const char *pszFilenameFmt, va_list args) 1015 1122 { … … 1113 1220 pLoggerInt->pfnPhase = pfnPhase; 1114 1221 pLoggerInt->hFile = NIL_RTFILE; 1222 pLoggerInt->fLogOpened = false; 1115 1223 pLoggerInt->cHistory = cHistory; 1116 1224 if (cbHistoryFileMax == 0) … … 1122 1230 else 1123 1231 pLoggerInt->cSecsHistoryTimeSlot = cSecsHistoryTimeSlot; 1232 1233 if (pOutputIf) 1234 { 1235 pLoggerInt->pOutputIf = pOutputIf; 1236 pLoggerInt->pvOutputIfUser = pvOutputIfUser; 1237 } 1238 else 1239 { 1240 /* Use the default interface for output logging. */ 1241 pLoggerInt->pOutputIf = &g_LogOutputIfDef; 1242 pLoggerInt->pvOutputIfUser = pLoggerInt; 1243 } 1244 1124 1245 # else /* !IN_RING3 */ 1125 1246 RT_NOREF_PV(pfnPhase); RT_NOREF_PV(cHistory); RT_NOREF_PV(cbHistoryFileMax); RT_NOREF_PV(cSecsHistoryTimeSlot); … … 1318 1439 } 1319 1440 # ifdef IN_RING3 1320 RTFileClose(pLoggerInt->hFile);1441 pLoggerInt->pOutputIf->pfnClose(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser); 1321 1442 # endif 1322 1443 # if defined(RT_ARCH_X86) && !defined(LOG_USE_C99) … … 1350 1471 0 /*cBufDescs*/, NULL /*paBufDescs*/, fDestFlags, 1351 1472 NULL /*pfnPhase*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*cSecsHistoryTimeSlot*/, 1473 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 1352 1474 NULL /*pErrInfo*/, pszFilenameFmt, va); 1353 1475 va_end(va); … … 1401 1523 */ 1402 1524 if ( (pLoggerInt->fDestFlags & RTLOGDEST_FILE) 1403 && pLoggerInt-> hFile != NIL_RTFILE)1525 && pLoggerInt->fLogOpened) 1404 1526 pLoggerInt->pfnPhase(&pLoggerInt->Core, RTLOGPHASE_END, rtlogPhaseMsgLocked); 1405 1527 … … 1407 1529 * Close output stuffs. 1408 1530 */ 1409 if (pLoggerInt->hFile != NIL_RTFILE) 1410 { 1411 int rc2 = RTFileClose(pLoggerInt->hFile); 1412 AssertRC(rc2); 1531 if (pLoggerInt->fLogOpened) 1532 { 1533 int rc2 = pLoggerInt->pOutputIf->pfnClose(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser); 1413 1534 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 1414 1535 rc = rc2; 1415 pLoggerInt-> hFile = NIL_RTFILE;1536 pLoggerInt->fLogOpened = false; 1416 1537 } 1417 1538 # endif … … 2443 2564 # ifdef IN_RING3 2444 2565 if ( pLoggerInt->fDestFlags & RTLOGDEST_FILE 2445 && pLoggerInt->hFile == NIL_RTFILE)2566 && !pLoggerInt->fLogOpened) 2446 2567 { 2447 2568 rc = rtR3LogOpenFileDestination(pLoggerInt, pErrInfo); … … 2654 2775 else 2655 2776 { 2656 RTFileDelete(pLoggerInt->szFilename); 2777 pLoggerInt->pOutputIf->pfnDelete(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2778 pLoggerInt->szFilename); 2657 2779 fOpen |= RTFILE_O_CREATE; 2658 2780 } … … 2663 2785 2664 2786 unsigned cBackoff = 0; 2665 int rc = RTFileOpen(&pLoggerInt->hFile, pLoggerInt->szFilename, fOpen); 2787 int rc = pLoggerInt->pOutputIf->pfnOpen(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2788 pLoggerInt->szFilename, fOpen); 2666 2789 while ( ( rc == VERR_SHARING_VIOLATION 2667 2790 || (rc == VERR_ALREADY_EXISTS && !(pLoggerInt->fFlags & RTLOGFLAGS_APPEND))) … … 2670 2793 RTThreadSleep(g_acMsLogBackoff[cBackoff++]); 2671 2794 if (!(pLoggerInt->fFlags & RTLOGFLAGS_APPEND)) 2672 RTFileDelete(pLoggerInt->szFilename); 2673 rc = RTFileOpen(&pLoggerInt->hFile, pLoggerInt->szFilename, fOpen); 2795 pLoggerInt->pOutputIf->pfnDelete(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2796 pLoggerInt->szFilename); 2797 rc = pLoggerInt->pOutputIf->pfnOpen(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2798 pLoggerInt->szFilename, fOpen); 2674 2799 } 2675 2800 if (RT_SUCCESS(rc)) 2676 2801 { 2677 rc = RTFileQuerySize(pLoggerInt->hFile, &pLoggerInt->cbHistoryFileWritten); 2802 pLoggerInt->fLogOpened = true; 2803 2804 rc = pLoggerInt->pOutputIf->pfnQuerySize(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2805 &pLoggerInt->cbHistoryFileWritten); 2678 2806 if (RT_FAILURE(rc)) 2679 2807 { … … 2685 2813 else 2686 2814 { 2687 pLoggerInt-> hFile = NIL_RTFILE;2815 pLoggerInt->fLogOpened = false; 2688 2816 RTErrInfoSetF(pErrInfo, rc, N_("could not open file '%s' (fOpen=%#x)"), pLoggerInt->szFilename, fOpen); 2689 2817 } … … 2734 2862 * Close the old log file. 2735 2863 */ 2736 if (pLoggerInt-> hFile != NIL_RTFILE)2864 if (pLoggerInt->fLogOpened) 2737 2865 { 2738 2866 /* Use the callback to generate some final log contents, but only if … … 2746 2874 pLoggerInt->fDestFlags = fODestFlags; 2747 2875 } 2748 RTFileClose(pLoggerInt->hFile); 2749 pLoggerInt-> hFile = NIL_RTFILE;2876 2877 pLoggerInt->pOutputIf->pfnClose(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser); 2750 2878 } 2751 2879 … … 2767 2895 2768 2896 unsigned cBackoff = 0; 2769 int rc = RTFileRename(szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE); 2897 int rc = pLoggerInt->pOutputIf->pfnRename(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2898 szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE); 2770 2899 while ( rc == VERR_SHARING_VIOLATION 2771 2900 && cBackoff < RT_ELEMENTS(g_acMsLogBackoff)) 2772 2901 { 2773 2902 RTThreadSleep(g_acMsLogBackoff[cBackoff++]); 2774 rc = RTFileRename(szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE); 2903 rc = pLoggerInt->pOutputIf->pfnRename(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 2904 szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE); 2775 2905 } 2776 2906 2777 2907 if (rc == VERR_FILE_NOT_FOUND) 2778 RTFileDelete(szNewName);2908 pLoggerInt->pOutputIf->pfnDelete(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, szNewName); 2779 2909 } 2780 2910 … … 2786 2916 char szExcessName[sizeof(pLoggerInt->szFilename) + 32]; 2787 2917 RTStrPrintf(szExcessName, sizeof(szExcessName), "%s.%u", pLoggerInt->szFilename, i); 2788 int rc = RTFileDelete(szExcessName);2918 int rc = pLoggerInt->pOutputIf->pfnDelete(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, szExcessName); 2789 2919 if (RT_FAILURE(rc)) 2790 2920 break; … … 2846 2976 2847 2977 /* If the file is not open then rotation is not set up. */ 2848 if ( pLoggerInt->hFile == NIL_RTFILE)2978 if (!pLoggerInt->fLogOpened) 2849 2979 { 2850 2980 pLoggerInt->cbHistoryFileWritten = 0; … … 3154 3284 if ((pLoggerInt->fDestFlags & (RTLOGDEST_FILE | RTLOGDEST_RINGBUF)) == RTLOGDEST_FILE) 3155 3285 { 3156 if (pLoggerInt-> hFile != NIL_RTFILE)3286 if (pLoggerInt->fLogOpened) 3157 3287 { 3158 RTFileWrite(pLoggerInt->hFile, pchToFlush, cchToFlush, NULL); 3288 pLoggerInt->pOutputIf->pfnWrite(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser, 3289 pchToFlush, cchToFlush, NULL /*pcbWritten*/); 3159 3290 if (pLoggerInt->fFlags & RTLOGFLAGS_FLUSH) 3160 RTFileFlush(pLoggerInt->hFile);3291 pLoggerInt->pOutputIf->pfnFlush(pLoggerInt->pOutputIf, pLoggerInt->pvOutputIfUser); 3161 3292 } 3162 3293 if (pLoggerInt->cHistory) -
trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
r93716 r94624 3330 3330 VMMLOGGER_BUFFER_COUNT, pR0Log->aBufDescs, RTLOGDEST_DUMMY, 3331 3331 NULL /*pfnPhase*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*cSecsHistoryTimeSlot*/, 3332 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 3332 3333 NULL /*pErrInfo*/, NULL /*pszFilenameFmt*/); 3333 3334 if (RT_SUCCESS(rc)) -
trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecService.cpp
r94525 r94624 3956 3956 logHeaderFooter /* pfnPhase */ , 3957 3957 10 /* cHistory */, 100 * _1M /* cbHistoryFileMax */, RT_SEC_1DAY /* cSecsHistoryTimeSlot */, 3958 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, 3958 3959 NULL /* pErrInfo */, "%s", szLogFile); 3959 3960 if (RT_SUCCESS(rc))
Note:
See TracChangeset
for help on using the changeset viewer.