vbox的更動 36408 路徑 trunk/src/VBox/Runtime/common
- 時間撮記:
- 2011-3-24 下午04:25:47 (14 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/common/log/log.cpp
r36344 r36408 79 79 } RTLOGOUTPUTPREFIXEDARGS, *PRTLOGOUTPUTPREFIXEDARGS; 80 80 81 #ifdef IN_RING3 82 /** 83 * File logging bits for the logger. 84 */ 85 typedef struct RTLOGGERFILE 86 { 87 /** Pointer to the function called when starting logging, and when 88 * ending or starting a new log file as part of history rotation. 89 * This can be NULL. */ 90 PFNRTLOGPHASE pfnPhase; 91 /** Handle to log file (if open). */ 92 RTFILE File; 93 /** Pointer to filename. 94 * (The memory is allocated in the same block as RTLOGGER.) */ 95 char *pszFilename; 96 /** Log file history settings: number of older files to keep. 97 * 0 means no history. */ 98 uint32_t cHistory; 99 /** Log file history settings: maximum amount of data to put in a file. */ 100 uint64_t cbHistoryFileMax; 101 /** Log file history settings: current amount of data in a file. */ 102 uint64_t cbHistoryFileWritten; 103 /** Log file history settings: maximum time to use a file (in seconds). */ 104 uint32_t cSecsHistoryTimeSlot; 105 /** Log file history settings: in what time slot was the file created. */ 106 uint32_t uHistoryTimeSlotStart; 107 } RTLOGGERFILE; 108 #endif /* IN_RING3 */ 109 81 110 82 111 /******************************************************************************* … … 96 125 static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars); 97 126 static DECLCALLBACK(size_t) rtLogOutputPrefixed(void *pv, const char *pachChars, size_t cbChars); 98 static void rtlogLoggerExV (PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args);127 static void rtlogLoggerExVLocked(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args); 99 128 100 129 … … 128 157 PRTLOGGER volatile pLogger; 129 158 } g_aPerThreadLoggers[8] = 130 { { NIL_RTNATIVETHREAD, 0, 0}, 159 { 160 { NIL_RTNATIVETHREAD, 0, 0}, 131 161 { NIL_RTNATIVETHREAD, 0, 0}, 132 162 { NIL_RTNATIVETHREAD, 0, 0}, … … 148 178 uint32_t fFlag; /**< The flag value. */ 149 179 bool fInverted; /**< Inverse meaning? */ 150 } 151 const s_aLogFlags[] = 180 } const s_aLogFlags[] = 152 181 { 153 182 { "disabled", sizeof("disabled" ) - 1, RTLOGFLAGS_DISABLED, false }, … … 239 268 } 240 269 241 242 270 #ifndef IN_RC 243 271 # ifdef IN_RING3 272 244 273 /** 245 274 * Logging to file, output callback. … … 255 284 return cbChars; 256 285 } 286 257 287 258 288 /** … … 283 313 } 284 314 315 285 316 /** 286 317 * Log phase callback function, assumes the lock is already held … … 298 329 299 330 va_start(args, pszFormat); 300 rtlogLoggerExV (pLogger, 0, ~0, pszFormat, args);331 rtlogLoggerExVLocked(pLogger, 0, ~0, pszFormat, args); 301 332 va_end(args); 302 333 } 303 334 304 /** 305 * Log phase callback function, assumes the lock is not held 335 336 /** 337 * Log phase callback function, assumes the lock is not held. 306 338 * 307 339 * @param pLogger The logger instance. … … 320 352 va_end(args); 321 353 } 354 322 355 # endif /* IN_RING3 */ 323 356 324 /**325 * Create a logger instance, comprehensive version.326 *327 * @returns iprt status code.328 *329 * @param ppLogger Where to store the logger instance.330 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.331 * @param pszGroupSettings The initial group settings.332 * @param pszEnvVarBase Base name for the environment variables for this instance.333 * @param cGroups Number of groups in the array.334 * @param papszGroups Pointer to array of groups. This must stick around for the life of the335 * logger instance.336 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.337 * @param pfnPhase Callback function for starting logging and for ending or starting a new file for log history rotation.338 * @param cHistory Number of old log files to keep when performing log history rotation.339 * @param cbHistoryFileMax Maximum size of log file when performing history rotation. 0=no size limit.340 * @param uHistoryTimeSlotLength Maximum time interval per log file when performing history rotation, in seconds. 0=no time limit.341 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.342 * @param cchErrorMsg The size of the error message buffer.343 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().344 * @param ... Format arguments.345 */346 357 RTDECL(int) RTLogCreateExV(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings, 347 358 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 348 359 uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory, 349 uint64_t cbHistoryFileMax, uint32_t uHistoryTimeSlotLength,360 uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot, 350 361 char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args) 351 362 { … … 358 369 */ 359 370 if ( (cGroups && !papszGroups) 360 || !VALID_PTR(ppLogger) 361 ) 371 || !VALID_PTR(ppLogger) ) 362 372 { 363 373 AssertMsgFailed(("Invalid parameters!\n")); … … 368 378 if (pszErrorMsg) 369 379 RTStrPrintf(pszErrorMsg, cchErrorMsg, N_("unknown error")); 380 381 AssertMsgReturn(cHistory < _1M, ("%#x", cHistory), VERR_OUT_OF_RANGE); 370 382 371 383 /* … … 397 409 else 398 410 pLogger->pFile->cbHistoryFileMax = cbHistoryFileMax; 399 if ( uHistoryTimeSlotLength== 0)400 pLogger->pFile-> uHistoryTimeSlotLength= UINT32_MAX;411 if (cSecsHistoryTimeSlot == 0) 412 pLogger->pFile->cSecsHistoryTimeSlot = UINT32_MAX; 401 413 else 402 pLogger->pFile-> uHistoryTimeSlotLength = uHistoryTimeSlotLength;403 #else /* !IN_RING3 */414 pLogger->pFile->cSecsHistoryTimeSlot = cSecsHistoryTimeSlot; 415 #else /* !IN_RING3 */ 404 416 pLogger->pFile = NULL; 405 417 #endif /* !IN_RING3 */ … … 450 462 if (pszFilenameFmt) 451 463 { 464 /** @todo validate the length, fail on overflow. */ 452 465 RTStrPrintfV(pLogger->pFile->pszFilename, RTPATH_MAX, pszFilenameFmt, args); 453 466 pLogger->fDestFlags |= RTLOGDEST_FILE; … … 500 513 { 501 514 rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg); 515 502 516 /* Rotate in case of appending to a too big log file, 503 *otherwise this simply doesn't do anything. */517 otherwise this simply doesn't do anything. */ 504 518 rtlogRotate(pLogger, 0, true /* fFirst */); 505 519 } … … 509 523 pLogger->pFile->cbHistoryFileWritten = UINT64_MAX; 510 524 rtlogRotate(pLogger, 0, true /* fFirst */); 525 511 526 /* If the file is not open then rotation is not set up. */ 512 527 if (pLogger->pFile->File == NIL_RTFILE) … … 521 536 Assert(VALID_PTR(pLogger->pFile->pfnPhase) || pLogger->pFile->pfnPhase == NULL); 522 537 if (pLogger->pFile->pfnPhase) 523 p fnPhase(pLogger, RTLOGPHASE_BEGIN, rtlogPhaseMsgNormal);538 pLogger->pFile->pfnPhase(pLogger, RTLOGPHASE_BEGIN, rtlogPhaseMsgNormal); 524 539 #endif /* IN_RING3 */ 525 540 … … 570 585 571 586 572 /**573 * Create a logger instance.574 *575 * @returns iprt status code.576 *577 * @param ppLogger Where to store the logger instance.578 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.579 * @param pszGroupSettings The initial group settings.580 * @param pszEnvVarBase Base name for the environment variables for this instance.581 * @param cGroups Number of groups in the array.582 * @param papszGroups Pointer to array of groups. This must stick around for the life of the583 * logger instance.584 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.585 * @param pfnPhase Callback function for starting logging and for ending or starting a new file for log history rotation.586 * @param cHistory Number of old log files to keep when performing log history rotation.587 * @param cbHistoryFileMax Maximum size of log file when performing history rotation. 0=no size limit.588 * @param uHistoryTimeSlotLength Maximum time interval per log file when performing history rotation, in seconds. 0=no time limit.589 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().590 * @param ... Format arguments.591 */592 587 RTDECL(int) RTLogCreate(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings, 593 588 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 594 uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory, 595 uint64_t cbHistoryFileMax, uint32_t uHistoryTimeSlotLength, 596 const char *pszFilenameFmt, ...) 589 uint32_t fDestFlags, const char *pszFilenameFmt, ...) 597 590 { 598 591 va_list args; … … 600 593 601 594 va_start(args, pszFilenameFmt); 602 rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, fDestFlags, pfnPhase, cHistory, cbHistoryFileMax, uHistoryTimeSlotLength, NULL, 0, pszFilenameFmt, args); 595 rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, 596 fDestFlags, NULL /*pfnPhase*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*cSecsHistoryTimeSlot*/, 597 NULL /*pszErrorMsg*/, 0 /*cchErrorMsg*/, pszFilenameFmt, args); 603 598 va_end(args); 604 599 return rc; … … 607 602 608 603 609 /**610 * Create a logger instance.611 *612 * @returns iprt status code.613 *614 * @param ppLogger Where to store the logger instance.615 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.616 * @param pszGroupSettings The initial group settings.617 * @param pszEnvVarBase Base name for the environment variables for this instance.618 * @param cGroups Number of groups in the array.619 * @param papszGroups Pointer to array of groups. This must stick around for the life of the620 * logger instance.621 * @param fDestFlags The destination flags. RTLOGDEST_FILE is ORed if pszFilenameFmt specified.622 * @param pfnPhase Callback function for starting logging and for ending or starting a new file for log history rotation.623 * @param cHistory Number of old log files to keep when performing log history rotation.624 * @param cbHistoryFileMax Maximum size of log file when performing history rotation. 0=no size limit.625 * @param uHistoryTimeSlotLength Maximum time interval per log file when performing history rotation, in seconds. 0=no time limit.626 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL.627 * @param cchErrorMsg The size of the error message buffer.628 * @param pszFilenameFmt Log filename format string. Standard RTStrFormat().629 * @param ... Format arguments.630 */631 604 RTDECL(int) RTLogCreateEx(PRTLOGGER *ppLogger, uint32_t fFlags, const char *pszGroupSettings, 632 605 const char *pszEnvVarBase, unsigned cGroups, const char * const * papszGroups, 633 606 uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory, 634 uint64_t cbHistoryFileMax, uint32_t uHistoryTimeSlotLength,607 uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot, 635 608 char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...) 636 609 { … … 639 612 640 613 va_start(args, pszFilenameFmt); 641 rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, fDestFlags, pfnPhase, cHistory, cbHistoryFileMax, uHistoryTimeSlotLength, pszErrorMsg, cchErrorMsg, pszFilenameFmt, args); 614 rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups, 615 fDestFlags, pfnPhase, cHistory, cbHistoryFileMax, cSecsHistoryTimeSlot, 616 pszErrorMsg, cchErrorMsg, pszFilenameFmt, args); 642 617 va_end(args); 643 618 return rc; … … 688 663 * Add end of logging message. 689 664 */ 690 if (pLogger->fDestFlags & RTLOGDEST_FILE && pLogger->pFile->File != NIL_RTFILE) 665 if ( (pLogger->fDestFlags & RTLOGDEST_FILE) 666 && pLogger->pFile->File != NIL_RTFILE) 691 667 pLogger->pFile->pfnPhase(pLogger, RTLOGPHASE_END, rtlogPhaseMsgLocked); 692 668 … … 1612 1588 RT_EXPORT_SYMBOL(RTLogSetBuffering); 1613 1589 1614 1615 1616 1590 #ifndef IN_RC 1591 1617 1592 /** 1618 1593 * Get the current log flags as a string. … … 1741 1716 if (!pszEnd) 1742 1717 pszEnd = strchr(pszVar, '\0'); 1743 # ifndef IN_RING01718 # ifdef IN_RING3 1744 1719 size_t cch = pszEnd - pszVar; 1745 1720 … … 1773 1748 if (!fNo) 1774 1749 { 1775 char szTmp[32]; 1750 uint32_t cHistory = 0; 1751 char szTmp[32]; 1776 1752 int rc = RTStrCopyEx(szTmp, sizeof(szTmp), pszVar, cch); 1777 1753 if (RT_SUCCESS(rc)) 1778 rc = RTStrToUInt32Full(szTmp, 0, &pLogger->pFile->cHistory); 1779 if (RT_FAILURE(rc)) 1780 AssertMsgFailedReturn(("Invalid history value %s (%Rrc)!\n", 1781 szTmp, rc), rc); 1754 rc = RTStrToUInt32Full(szTmp, 0, &cHistory); 1755 AssertMsgReturn(RT_SUCCESS(rc) && cHistory < _1M, ("Invalid history value %s (%Rrc)!\n", szTmp, rc), rc); 1756 pLogger->pFile->cHistory = cHistory; 1782 1757 } 1783 1758 else … … 1792 1767 if (RT_SUCCESS(rc)) 1793 1768 rc = RTStrToUInt64Full(szTmp, 0, &pLogger->pFile->cbHistoryFileMax); 1794 if (RT_FAILURE(rc)) 1795 AssertMsgFailedReturn(("Invalid history file size value %s (%Rrc)!\n", 1796 szTmp, rc), rc); 1769 AssertMsgRCReturn(rc, ("Invalid history file size value %s (%Rrc)!\n", szTmp, rc), rc); 1797 1770 if (pLogger->pFile->cbHistoryFileMax == 0) 1798 1771 pLogger->pFile->cbHistoryFileMax = UINT64_MAX; … … 1808 1781 int rc = RTStrCopyEx(szTmp, sizeof(szTmp), pszVar, cch); 1809 1782 if (RT_SUCCESS(rc)) 1810 rc = RTStrToUInt32Full(szTmp, 0, &pLogger->pFile->uHistoryTimeSlotLength); 1811 if (RT_FAILURE(rc)) 1812 AssertMsgFailedReturn(("Invalid history timespan value %s (%Rrc)!\n", 1813 szTmp, rc), rc); 1814 if (pLogger->pFile->uHistoryTimeSlotLength == 0) 1815 pLogger->pFile->uHistoryTimeSlotLength = UINT32_MAX; 1783 rc = RTStrToUInt32Full(szTmp, 0, &pLogger->pFile->cSecsHistoryTimeSlot); 1784 AssertMsgRCReturn(rc, ("Invalid history time slot value %s (%Rrc)!\n", szTmp, rc), rc); 1785 if (pLogger->pFile->cSecsHistoryTimeSlot == 0) 1786 pLogger->pFile->cSecsHistoryTimeSlot = UINT32_MAX; 1816 1787 } 1817 1788 else 1818 pLogger->pFile-> uHistoryTimeSlotLength= UINT32_MAX;1789 pLogger->pFile->cSecsHistoryTimeSlot = UINT32_MAX; 1819 1790 } 1820 1791 else … … 1822 1793 fNo ? "no" : "", s_aLogDst[i].pszInstr), 1823 1794 VERR_INVALID_PARAMETER); 1824 # endif1795 # endif /* IN_RING3 */ 1825 1796 pszVar = pszEnd + (*pszEnd != '\0'); 1826 1797 } … … 1860 1831 unsigned i; 1861 1832 1862 Assert(cchBuf); 1833 AssertReturn(cchBuf, VERR_INVALID_PARAMETER); 1834 *pszBuf = '\0'; 1863 1835 1864 1836 /* … … 1869 1841 pLogger = RTLogDefaultInstance(); 1870 1842 if (!pLogger) 1871 {1872 *pszBuf = '\0';1873 1843 return VINF_SUCCESS; 1874 } 1875 } 1876 #define APPEND_PSZ(psz,cch) do { memcpy(pszBuf, (psz), (cch)); pszBuf += (cch); cchBuf -= (cch); } while (0) 1877 #define APPEND_SZ(sz) APPEND_PSZ(sz, sizeof(sz) - 1) 1878 #define APPEND_CH(ch) do { *pszBuf++ = (ch); cchBuf--; } while (0) 1844 } 1879 1845 1880 1846 /* … … 1885 1851 if (s_aLogDst[i].fFlag & fDestFlags) 1886 1852 { 1887 size_t cchInstr = s_aLogDst[i].cchInstr; 1888 if (cchInstr + fNotFirst + 1 > cchBuf) 1853 if (fNotFirst) 1889 1854 { 1890 rc = VERR_BUFFER_OVERFLOW; 1891 break; 1855 rc = RTStrCopyP(&pszBuf, &cchBuf, " "); 1856 if (RT_FAILURE(rc)) 1857 return rc; 1892 1858 } 1893 if (fNotFirst) 1894 APPEND_CH(' '); 1859 rc = RTStrCopyP(&pszBuf, &cchBuf, s_aLogDst[i].pszInstr); 1860 if (RT_FAILURE(rc)) 1861 return rc; 1895 1862 fNotFirst = true; 1896 APPEND_PSZ(s_aLogDst[i].pszInstr, cchInstr);1897 1863 } 1898 1864 … … 1902 1868 */ 1903 1869 if ( (fDestFlags & RTLOGDEST_FILE) 1904 && VALID_PTR(pLogger->pFile->pszFilename) 1905 && RT_SUCCESS(rc)) 1906 { 1907 size_t cchFilename = strlen(pLogger->pFile->pszFilename); 1908 if (cchFilename + sizeof("file=") - 1 + fNotFirst + 1 <= cchBuf) 1909 { 1910 if (fNotFirst) 1911 APPEND_SZ(" file="); 1912 else 1913 APPEND_SZ("file="); 1914 APPEND_PSZ(pLogger->pFile->pszFilename, cchFilename); 1915 } 1916 else 1917 rc = VERR_BUFFER_OVERFLOW; 1918 } 1919 #endif 1920 1921 #undef APPEND_PSZ 1922 #undef APPEND_SZ 1923 #undef APPEND_CH 1924 1925 *pszBuf = '\0'; 1926 return rc; 1870 && VALID_PTR(pLogger->pFile->pszFilename)) 1871 { 1872 rc = RTStrCopyP(&pszBuf, &cchBuf, fNotFirst ? " file=" : "file="); 1873 if (RT_FAILURE(rc)) 1874 return rc; 1875 rc = RTStrCopyP(&pszBuf, &cchBuf, pLogger->pFile->pszFilename); 1876 if (RT_FAILURE(rc)) 1877 return rc; 1878 fNotFirst = true; 1879 } 1880 1881 if (fDestFlags & RTLOGDEST_FILE) 1882 { 1883 char szNum[32]; 1884 if (pLogger->pFile->cHistory) 1885 { 1886 RTStrPrintf(szNum, sizeof(szNum), fNotFirst ? "history=%u" : " history=%u", pLogger->pFile->cHistory); 1887 rc = RTStrCopyP(&pszBuf, &cchBuf, szNum); 1888 if (RT_FAILURE(rc)) 1889 return rc; 1890 } 1891 if (pLogger->pFile->cbHistoryFileMax != UINT64_MAX) 1892 { 1893 RTStrPrintf(szNum, sizeof(szNum), fNotFirst ? "histsize=%llu" : " histsize=%llu", pLogger->pFile->cbHistoryFileMax); 1894 rc = RTStrCopyP(&pszBuf, &cchBuf, szNum); 1895 if (RT_FAILURE(rc)) 1896 return rc; 1897 } 1898 if (pLogger->pFile->cSecsHistoryTimeSlot != UINT32_MAX) 1899 { 1900 RTStrPrintf(szNum, sizeof(szNum), fNotFirst ? "histtime=%llu" : " histtime=%llu", pLogger->pFile->cSecsHistoryTimeSlot); 1901 rc = RTStrCopyP(&pszBuf, &cchBuf, szNum); 1902 if (RT_FAILURE(rc)) 1903 return rc; 1904 } 1905 } 1906 #endif /* IN_RING3 */ 1907 1908 return VINF_SUCCESS; 1927 1909 } 1928 1910 RT_EXPORT_SYMBOL(RTLogGetDestinations); 1911 1929 1912 #endif /* !IN_RC */ 1930 1931 1913 1932 1914 /** … … 2229 2211 * Call worker. 2230 2212 */ 2231 rtlogLoggerExV (pLogger, fFlags, iGroup, pszFormat, args);2213 rtlogLoggerExVLocked(pLogger, fFlags, iGroup, pszFormat, args); 2232 2214 2233 2215 /* … … 2399 2381 RT_EXPORT_SYMBOL(RTLogPrintfV); 2400 2382 2401 2402 2383 #ifdef IN_RING3 2384 2403 2385 /** 2404 2386 * Opens/creates the log file. 2405 2387 * 2406 * @param pLogger The logger instance to update. NULL is not allowed! 2407 * @param pszErrorMsg A buffer which is filled with an error message if something fails. May be NULL. 2408 * @param cchErrorMsg The size of the error message buffer. 2388 * @param pLogger The logger instance to update. NULL is not allowed! 2389 * @param pszErrorMsg A buffer which is filled with an error message if 2390 * something fails. May be NULL. 2391 * @param cchErrorMsg The size of the error message buffer. 2409 2392 */ 2410 2393 static int rtlogFileOpen(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg) … … 2417 2400 if (pLogger->fFlags & RTLOGFLAGS_WRITE_THROUGH) 2418 2401 fOpen |= RTFILE_O_WRITE_THROUGH; 2402 2419 2403 int rc = RTFileOpen(&pLogger->pFile->File, pLogger->pFile->pszFilename, fOpen); 2420 2404 if (RT_FAILURE(rc)) … … 2440 2424 /** 2441 2425 * Closes, rotates and opens the log files if necessary. 2442 * Used by the rtlogFlush() function. 2426 * 2427 * Used by the rtlogFlush() function as well as RTLogCreateExV. 2443 2428 * 2444 2429 * @param pLogger The logger instance to update. NULL is not allowed! 2445 2430 * @param uTimeSlit Current time slot (for tikme based rotation). 2446 * @param fFirst Flag whether this is the beginning of logging. 2431 * @param fFirst Flag whether this is the beginning of logging, i.e. 2432 * called from RTLogCreateExV. Prevents pfnPhase from 2433 * being called. 2447 2434 */ 2448 2435 static void rtlogRotate(PRTLOGGER pLogger, uint32_t uTimeSlot, bool fFirst) … … 2457 2444 return; 2458 2445 2459 /* Save "disabled" log flag and make sure logging is disabled. 2446 /* 2447 * Save "disabled" log flag and make sure logging is disabled. 2460 2448 * The logging in the functions called during log file history 2461 * rotation would cause severe trouble otherwise. */ 2462 uint32_t fOFlags = pLogger->fFlags; 2449 * rotation would cause severe trouble otherwise. 2450 */ 2451 uint32_t const fSavedFlags = pLogger->fFlags; 2463 2452 pLogger->fFlags |= RTLOGFLAGS_DISABLED; 2464 2453 2465 /* Disable log rotation temporarily, otherwise with extreme settings and 2466 * chatty phase logging we could run into endless rotation. */ 2467 uint32_t cOHistory = pLogger->pFile->cHistory; 2454 /* 2455 * Disable log rotation temporarily, otherwise with extreme settings and 2456 * chatty phase logging we could run into endless rotation. 2457 */ 2458 uint32_t const cSavedHistory = pLogger->pFile->cHistory; 2468 2459 pLogger->pFile->cHistory = 0; 2469 2460 2470 /* Close the old log file. */ 2461 /* 2462 * Close the old log file. 2463 */ 2471 2464 if (pLogger->pFile->File != NIL_RTFILE) 2472 2465 { … … 2485 2478 } 2486 2479 2487 /* Rotate the log files. */ 2488 if (cOHistory) 2489 { 2490 for (uint32_t i = cOHistory - 1; i + 1 > 0; i--) 2480 if (cSavedHistory) 2481 { 2482 /* 2483 * Rotate the log files. 2484 */ 2485 for (uint32_t i = cSavedHistory - 1; i + 1 > 0; i--) 2491 2486 { 2492 2487 char szOldName[RTPATH_MAX]; … … 2501 2496 RTFileDelete(szNewName); 2502 2497 } 2503 } 2504 /* Delete excess log files. */ 2505 for (uint32_t i = cOHistory + 1; i++; ) 2506 { 2507 char szExcessName[RTPATH_MAX]; 2508 RTStrPrintf(szExcessName, sizeof(szExcessName), "%s.%u", pLogger->pFile->pszFilename, i); 2509 int rc = RTFileDelete(szExcessName); 2510 if (RT_FAILURE(rc)) 2511 break; 2512 } 2513 2514 /* Update logger state and create new log file. */ 2498 2499 /* 2500 * Delete excess log files. 2501 */ 2502 for (uint32_t i = cSavedHistory + 1; ; i++) 2503 { 2504 char szExcessName[RTPATH_MAX]; 2505 RTStrPrintf(szExcessName, sizeof(szExcessName), "%s.%u", pLogger->pFile->pszFilename, i); 2506 int rc = RTFileDelete(szExcessName); 2507 if (RT_FAILURE(rc)) 2508 break; 2509 } 2510 } 2511 2512 /* 2513 * Update logger state and create new log file. 2514 */ 2515 2515 pLogger->pFile->cbHistoryFileWritten = 0; 2516 2516 pLogger->pFile->uHistoryTimeSlotStart = uTimeSlot; 2517 2517 rtlogFileOpen(pLogger, NULL, 0); 2518 2518 2519 /* Use the callback to generate some initial log contents, but only if this 2520 * is a rotation with a fully set up logger. Leave the other case to the 2521 * RTLogCreateExV function. */ 2519 /* 2520 * Use the callback to generate some initial log contents, but only if this 2521 * is a rotation with a fully set up logger. Leave the other case to the 2522 * RTLogCreateExV function. 2523 */ 2522 2524 if (pLogger->pFile->pfnPhase && !fFirst) 2523 2525 { 2524 uint32_t fODestFlags = pLogger->fDestFlags;2526 uint32_t const fSavedDestFlags = pLogger->fDestFlags; 2525 2527 pLogger->fDestFlags &= RTLOGDEST_FILE; 2526 2528 pLogger->pFile->pfnPhase(pLogger, RTLOGPHASE_POSTROTATE, rtlogPhaseMsgLocked); 2527 pLogger->fDestFlags = fODestFlags; 2528 } 2529 2530 /* Restore log rotation to the previous value. */ 2531 pLogger->pFile->cHistory = cOHistory; 2532 2533 /* Restore the log flags to the previous value. */ 2534 pLogger->fFlags = fOFlags; 2535 } 2529 pLogger->fDestFlags = fSavedDestFlags; 2530 } 2531 2532 /* Restore saved values. */ 2533 pLogger->pFile->cHistory = cSavedHistory; 2534 pLogger->fFlags = fSavedFlags; 2535 } 2536 2536 2537 #endif /* IN_RING3 */ 2537 2538 2538 2539 2539 /** … … 2588 2588 pLogger->offScratch = 0; 2589 2589 2590 # ifdef IN_RING3 2591 /* Rotate the log file if configured. Must be done after everything is 2590 #ifdef IN_RING3 2591 /* 2592 * Rotate the log file if configured. Must be done after everything is 2592 2593 * flushed, since this will also use logging/flushing to write the header 2593 * and footer messages. */ 2594 if ((pLogger->fDestFlags & RTLOGDEST_FILE) && pLogger->pFile->cHistory) 2595 { 2594 * and footer messages. 2595 */ 2596 if ( (pLogger->fDestFlags & RTLOGDEST_FILE) 2597 && pLogger->pFile->cHistory) 2596 2598 rtlogRotate(pLogger, 2597 RTTimeProgramSecTS() / pLogger->pFile-> uHistoryTimeSlotLength,2599 RTTimeProgramSecTS() / pLogger->pFile->cSecsHistoryTimeSlot, 2598 2600 false /* fFirst */); 2599 }2600 2601 #endif 2601 2602 } … … 3066 3067 } 3067 3068 3069 3068 3070 /** 3069 3071 * Write to a logger instance (worker function). … … 3080 3082 * @param args Format arguments. 3081 3083 */ 3082 static void rtlogLoggerExV (PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args)3084 static void rtlogLoggerExVLocked(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args) 3083 3085 { 3084 3086 /* … … 3089 3091 RTLOGOUTPUTPREFIXEDARGS OutputArgs; 3090 3092 OutputArgs.pLogger = pLogger; 3091 OutputArgs.iGroup = iGroup;3092 OutputArgs.fFlags = fFlags;3093 OutputArgs.iGroup = iGroup; 3094 OutputArgs.fFlags = fFlags; 3093 3095 RTLogFormatV(rtLogOutputPrefixed, &OutputArgs, pszFormat, args); 3094 3096 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器