diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-03 21:49:35 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-03 21:49:35 +0000 |
| commit | 3c18a66ef601d90f08ea622021cb02bafab1601b (patch) | |
| tree | ccb8ffec434c2c1eb9e0357c5692ee8aca42e159 /src/util.cpp | |
| parent | 4c6572f01d995e632338d7fb921962bb8f600eed (diff) | |
| parent | 74f1d8598a6f603fdfaf6c0487375c40166b76ec (diff) | |
merge: !2 fix/log-rotation into deploy/all-2026-08-24
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/src/util.cpp b/src/util.cpp index 0cd0133..60142be 100644 --- a/src/util.cpp +++ b/src/util.cpp | |||
| @@ -7,6 +7,12 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | bool fDebug = false; | 9 | bool fDebug = false; |
| 10 | bool fDebugRelay = false; | ||
| 11 | |||
| 12 | // In-process cap for debug.log, in bytes. Default matches the 1G trigger of | ||
| 13 | // the shipped logrotate policy so a long-running node stays bounded even | ||
| 14 | // without it; -maxdebugfilesize=N (MB) tunes it, 0 disables. | ||
| 15 | int64 nMaxDebugFileSize = 1024 * 1024 * (int64)1024; | ||
| 10 | 16 | ||
| 11 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
| 12 | // Categorized, burst-collapsing logging -- see the LogPrint doc comment in | 18 | // Categorized, burst-collapsing logging -- see the LogPrint doc comment in |
| @@ -26,10 +32,22 @@ static bool LogCategoryDefaultOn(const char* category) | |||
| 26 | strcmp(category, "payout") == 0; | 32 | strcmp(category, "payout") == 0; |
| 27 | } | 33 | } |
| 28 | 34 | ||
| 35 | // Categories so noisy they drown out everything else even under -debug: | ||
| 36 | // per-message send traces, wallet relay rebroadcasts, raw CBlock dumps and | ||
| 37 | // per-address discovery lines made up ~90% of a 13-hour production capture | ||
| 38 | // (issue #35). They need /debugrelay, not merely /debug. | ||
| 39 | static bool LogCategoryVerboseOnly(const char* category) | ||
| 40 | { | ||
| 41 | return strcmp(category, "relay") == 0 || | ||
| 42 | strcmp(category, "nostrdiscovery") == 0; | ||
| 43 | } | ||
| 44 | |||
| 29 | bool LogAcceptsCategory(const char* category) | 45 | bool LogAcceptsCategory(const char* category) |
| 30 | { | 46 | { |
| 31 | if (LogCategoryDefaultOn(category)) | 47 | if (LogCategoryDefaultOn(category)) |
| 32 | return true; | 48 | return true; |
| 49 | if (LogCategoryVerboseOnly(category)) | ||
| 50 | return fDebugRelay; | ||
| 33 | return fDebug; | 51 | return fDebug; |
| 34 | } | 52 | } |
| 35 | 53 | ||
| @@ -397,13 +415,37 @@ bool FileExists(const char* psz) | |||
| 397 | #endif | 415 | #endif |
| 398 | } | 416 | } |
| 399 | 417 | ||
| 400 | int GetFilesize(FILE* file) | 418 | #ifndef _WIN32 |
| 419 | // If off_t is 32 bits wide, ftello() truncates exactly like the int this | ||
| 420 | // function used to return. Fail the build rather than ship the silent | ||
| 421 | // version of the bug (32-bit hosts need -D_FILE_OFFSET_BITS=64). | ||
| 422 | static_assert(sizeof(off_t) >= 8, "GetFilesize needs a 64-bit off_t"); | ||
| 423 | #endif | ||
| 424 | |||
| 425 | // Returns the file's size in bytes, or -1 if it cannot be determined. | ||
| 426 | // | ||
| 427 | // This used to hold ftell()'s long in an int, so a file of 2 GiB or more came | ||
| 428 | // back negative. Its only caller is the debug.log roll in util.h, which skips | ||
| 429 | // the roll on a negative size -- i.e. rotation switched itself off for good at | ||
| 430 | // exactly the size the roll exists to prevent, and any cap of 2048 MB or more | ||
| 431 | // could never be exceeded at all. Both failures were silent. | ||
| 432 | int64 GetFilesize(FILE* file) | ||
| 401 | { | 433 | { |
| 402 | int nSavePos = ftell(file); | 434 | #ifdef _WIN32 |
| 403 | int nFilesize = -1; | 435 | __int64 nSavePos = _ftelli64(file); |
| 404 | if (fseek(file, 0, SEEK_END) == 0) | 436 | int64 nFilesize = -1; |
| 405 | nFilesize = ftell(file); | 437 | if (nSavePos >= 0 && _fseeki64(file, 0, SEEK_END) == 0) |
| 406 | fseek(file, nSavePos, SEEK_SET); | 438 | nFilesize = _ftelli64(file); |
| 439 | if (nSavePos >= 0) | ||
| 440 | _fseeki64(file, nSavePos, SEEK_SET); | ||
| 441 | #else | ||
| 442 | off_t nSavePos = ftello(file); | ||
| 443 | int64 nFilesize = -1; | ||
| 444 | if (nSavePos >= 0 && fseeko(file, 0, SEEK_END) == 0) | ||
| 445 | nFilesize = ftello(file); | ||
| 446 | if (nSavePos >= 0) | ||
| 447 | fseeko(file, nSavePos, SEEK_SET); | ||
| 448 | #endif | ||
| 407 | return nFilesize; | 449 | return nFilesize; |
| 408 | } | 450 | } |
| 409 | 451 | ||