Changeset 69745 in vbox
- Timestamp:
- Nov 18, 2017 8:52:38 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119145
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/log.h
r69105 r69745 457 457 /** Open files with no deny (share read, write, delete) on Windows. */ 458 458 RTLOGDEST_F_NO_DENY = 0x00010000, 459 /** Delay opening the log file, logging to the buffer untill 460 * RTLogClearFileDelayFlag is called. */ 461 RTLOGDEST_F_DELAY_FILE = 0x00020000, 459 462 /** Just a dummy flag to be used when no other flag applies. */ 460 463 RTLOGDEST_DUMMY = 0x20000000, … … 2269 2272 2270 2273 /** 2274 * Clear the file delay flag if set, opening the destination and flushing. 2275 * 2276 * @returns IPRT status code. 2277 * @param pLogger Logger instance (NULL for default logger). 2278 * @param pszValue The value to parse. 2279 * @param pErrInfo Where to return extended error info. Optional. 2280 */ 2281 RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo); 2282 2283 /** 2271 2284 * Get the current log destinations as a string. 2272 2285 * -
trunk/include/iprt/mangling.h
r69742 r69745 1234 1234 # define RTLogBackdoorPrintfV RT_MANGLER(RTLogBackdoorPrintfV) /* r0drv-guest */ 1235 1235 # define RTLogCalcSizeForR0 RT_MANGLER(RTLogCalcSizeForR0) 1236 # define RTLogClearFileDelayFlag RT_MANGLER(RTLogClearFileDelayFlag) 1236 1237 # define RTLogCloneRC RT_MANGLER(RTLogCloneRC) 1237 1238 # define RTLogComPrintf RT_MANGLER(RTLogComPrintf) -
trunk/src/VBox/Runtime/common/log/log.cpp
r69111 r69745 228 228 #endif 229 229 #ifdef IN_RING3 230 static int rtlogFileOpen(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg); 231 static void rtlogRotate(PRTLOGGER pLogger, uint32_t uTimeSlot, bool fFirst); 230 static int rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg); 232 231 #endif 233 232 #ifndef IN_RC 234 233 static void rtLogRingBufFlush(PRTLOGGER pLogger); 235 234 #endif 236 static void rtlogFlush(PRTLOGGER pLogger );235 static void rtlogFlush(PRTLOGGER pLogger, bool fNeedSpace); 237 236 static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars); 238 237 static DECLCALLBACK(size_t) rtLogOutputPrefixed(void *pv, const char *pachChars, size_t cbChars); … … 776 775 # endif 777 776 } 778 779 780 777 781 778 … … 947 944 */ 948 945 rc = VINF_SUCCESS; 946 if ((pLogger->fDestFlags & (RTLOGDEST_F_DELAY_FILE | RTLOGDEST_FILE)) == RTLOGDEST_F_DELAY_FILE) 947 pLogger->fDestFlags &= ~RTLOGDEST_F_DELAY_FILE; 949 948 # ifdef IN_RING3 950 if (pLogger->fDestFlags & RTLOGDEST_FILE) 951 { 952 if (pLogger->fFlags & RTLOGFLAGS_APPEND) 953 { 954 rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg); 955 956 /* Rotate in case of appending to a too big log file, 957 otherwise this simply doesn't do anything. */ 958 rtlogRotate(pLogger, 0, true /* fFirst */); 959 } 960 else 961 { 962 /* Force rotation if it is configured. */ 963 pLogger->pInt->cbHistoryFileWritten = UINT64_MAX; 964 rtlogRotate(pLogger, 0, true /* fFirst */); 965 966 /* If the file is not open then rotation is not set up. */ 967 if (pLogger->pInt->hFile == NIL_RTFILE) 968 { 969 pLogger->pInt->cbHistoryFileWritten = 0; 970 rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg); 971 } 972 } 973 } 974 # endif /* IN_RING3 */ 949 if ((pLogger->fDestFlags & (RTLOGDEST_FILE | RTLOGDEST_F_DELAY_FILE)) == RTLOGDEST_FILE) 950 rc = rtR3LogOpenFileDestination(pLogger, pszErrorMsg, cchErrorMsg); 951 # endif 975 952 976 953 if ((pLogger->fDestFlags & RTLOGDEST_RINGBUF) && RT_SUCCESS(rc)) … … 1102 1079 * Flush it. 1103 1080 */ 1104 rtlogFlush(pLogger );1081 rtlogFlush(pLogger, false /*fNeedSpace*/); 1105 1082 1106 1083 # ifdef IN_RING3 … … 2449 2426 2450 2427 /** 2428 * Clear the file delay flag if set, opening the destination and flushing. 2429 * 2430 * @returns IPRT status code. 2431 * @param pLogger Logger instance (NULL for default logger). 2432 * @param pszValue The value to parse. 2433 * @param pErrInfo Where to return extended error info. Optional. 2434 */ 2435 RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo) 2436 { 2437 /* 2438 * Resolve defaults. 2439 */ 2440 if (!pLogger) 2441 { 2442 pLogger = RTLogDefaultInstance(); 2443 if (!pLogger) 2444 return VINF_SUCCESS; 2445 } 2446 2447 /* 2448 * Do the work. 2449 */ 2450 int rc = rtlogLock(pLogger); 2451 if (RT_SUCCESS(rc)) 2452 { 2453 if (pLogger->fDestFlags & RTLOGDEST_F_DELAY_FILE) 2454 { 2455 pLogger->fDestFlags &= ~RTLOGDEST_F_DELAY_FILE; 2456 # ifdef IN_RING3 2457 if ( pLogger->fDestFlags & RTLOGDEST_FILE 2458 && pLogger->pInt->hFile == NIL_RTFILE) 2459 { 2460 int rc = rtR3LogOpenFileDestination(pLogger, NULL, 0); 2461 if (RT_SUCCESS(rc)) 2462 rtlogFlush(pLogger, false /*fNeedSpace*/); 2463 } 2464 # endif 2465 RT_NOREF(pErrInfo); /** @todo fix create API to use RTErrInfo */ 2466 } 2467 rtlogUnlock(pLogger); 2468 } 2469 return VINF_SUCCESS; 2470 } 2471 RT_EXPORT_SYMBOL(RTLogClearFileDelayFlag); 2472 2473 2474 /** 2451 2475 * Get the current log destinations as a string. 2452 2476 * … … 2605 2629 * Call worker. 2606 2630 */ 2607 rtlogFlush(pLogger );2631 rtlogFlush(pLogger, false /*fNeedSpace*/); 2608 2632 2609 2633 #ifndef IN_RC … … 3317 3341 } 3318 3342 3343 3344 /** 3345 * Worker for RTLogCreateExV and RTLogClearFileDelayFlag. 3346 * 3347 * This will later be used to reopen the file by RTLogDestinations. 3348 * 3349 * @returns IPRT status code. 3350 * @param pLogger The logger. 3351 * @param pszErrorMsg Where to return error info. Optional. 3352 * @param cchErrorMsg Size of @a pszErrorMsg buffer. 3353 */ 3354 static int rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg) 3355 { 3356 int rc; 3357 if (pLogger->fFlags & RTLOGFLAGS_APPEND) 3358 { 3359 rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg); 3360 3361 /* Rotate in case of appending to a too big log file, 3362 otherwise this simply doesn't do anything. */ 3363 rtlogRotate(pLogger, 0, true /* fFirst */); 3364 } 3365 else 3366 { 3367 /* Force rotation if it is configured. */ 3368 pLogger->pInt->cbHistoryFileWritten = UINT64_MAX; 3369 rtlogRotate(pLogger, 0, true /* fFirst */); 3370 3371 /* If the file is not open then rotation is not set up. */ 3372 if (pLogger->pInt->hFile == NIL_RTFILE) 3373 { 3374 pLogger->pInt->cbHistoryFileWritten = 0; 3375 rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg); 3376 } 3377 else 3378 rc = VINF_SUCCESS; 3379 } 3380 return rc; 3381 } 3382 3319 3383 #endif /* IN_RING3 */ 3320 3384 … … 3323 3387 * Writes the buffer to the given log device without checking for buffered 3324 3388 * data or anything. 3389 * 3325 3390 * Used by the RTLogFlush() function. 3326 3391 * 3327 3392 * @param pLogger The logger instance to write to. NULL is not allowed! 3328 */ 3329 static void rtlogFlush(PRTLOGGER pLogger) 3393 * @param fNeedSpace Set if the caller assumes space will be made available. 3394 */ 3395 static void rtlogFlush(PRTLOGGER pLogger, bool fNeedSpace) 3330 3396 { 3331 3397 uint32_t const cchScratch = pLogger->offScratch; 3332 3398 if (cchScratch == 0) 3333 3399 return; /* nothing to flush. */ 3400 NOREF(fNeedSpace); 3334 3401 3335 3402 #ifndef IN_RC … … 3345 3412 pLogger->offScratch = 0; /* empty the buffer. */ 3346 3413 } 3414 /* 3415 * In file delay mode, we ignore flush requests except when we're full 3416 * and the caller really needs some scratch space to get work done. 3417 */ 3347 3418 else 3419 # ifdef IN_RING3 3420 if (!(pLogger->fDestFlags & RTLOGDEST_F_DELAY_FILE)) 3421 # endif 3348 3422 #endif 3349 3423 { … … 3410 3484 #endif 3411 3485 } 3486 #ifdef IN_RING3 3487 else 3488 { 3489 /* 3490 * Delay file open but the caller really need some space. So, give him half a 3491 * buffer and insert a message indicating that we've dropped output. 3492 */ 3493 uint32_t offHalf = sizeof(pLogger->achScratch) / 2; 3494 if (cchScratch > offHalf) 3495 { 3496 if (pLogger->fFlags & RTLOGFLAGS_USECRLF) 3497 pLogger->achScratch[offHalf++] = '\r'; 3498 static const char s_szDropMsg[] = "\n[DROP DROP DROP]"; 3499 memcpy(&pLogger->achScratch[offHalf], RT_STR_TUPLE(s_szDropMsg)); 3500 offHalf += sizeof(s_szDropMsg) - 1; 3501 if (pLogger->fFlags & RTLOGFLAGS_USECRLF) 3502 pLogger->achScratch[offHalf++] = '\r'; 3503 pLogger->achScratch[offHalf++] = '\n'; 3504 3505 pLogger->offScratch = offHalf; 3506 } 3507 } 3508 #endif 3412 3509 } 3413 3510 … … 3455 3552 3456 3553 /* flush */ 3457 rtlogFlush(pLogger );3554 rtlogFlush(pLogger, true /*fNeedSpace*/); 3458 3555 } 3459 3556 … … 3552 3649 if (cb < 256 + 16) 3553 3650 { 3554 rtlogFlush(pLogger );3651 rtlogFlush(pLogger, true /*fNeedSpace*/); 3555 3652 offScratch = pLogger->offScratch; 3556 3653 cb = sizeof(pLogger->achScratch) - offScratch - 1; … … 3850 3947 else if (cb <= 0) 3851 3948 { 3852 rtlogFlush(pLogger );3949 rtlogFlush(pLogger, true /*fNeedSpace*/); 3853 3950 offScratch = pLogger->offScratch; 3854 3951 cb = sizeof(pLogger->achScratch) - offScratch - 1; … … 3953 4050 if ( !(pLogger->fFlags & RTLOGFLAGS_BUFFERED) 3954 4051 && pLogger->offScratch) 3955 rtlogFlush(pLogger );4052 rtlogFlush(pLogger, false /*fNeedSpace*/); 3956 4053 } 3957 4054
Note:
See TracChangeset
for help on using the changeset viewer.