Changeset View
Changeset View
Standalone View
Standalone View
src/logging.cpp
Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | void BCLog::Logger::ShrinkDebugFile() { | ||||
fs::path pathLog = GetDebugLogPath(); | fs::path pathLog = GetDebugLogPath(); | ||||
FILE *file = fsbridge::fopen(pathLog, "r"); | FILE *file = fsbridge::fopen(pathLog, "r"); | ||||
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE | // If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE | ||||
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes. | // trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes. | ||||
if (file && | if (file && | ||||
fs::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10)) { | fs::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10)) { | ||||
// Restart the file with some of the end. | // Restart the file with some of the end. | ||||
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0); | std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0); | ||||
fseek(file, -((long)vch.size()), SEEK_END); | if (fseek(file, -((long)vch.size()), SEEK_END)) { | ||||
LogPrintf("Failed to shrink debug log file: fseek(...) failed\n"); | |||||
fclose(file); | |||||
return; | |||||
} | |||||
int nBytes = fread(vch.data(), 1, vch.size(), file); | int nBytes = fread(vch.data(), 1, vch.size(), file); | ||||
fclose(file); | fclose(file); | ||||
file = fsbridge::fopen(pathLog, "w"); | file = fsbridge::fopen(pathLog, "w"); | ||||
if (file) { | if (file) { | ||||
fwrite(vch.data(), 1, nBytes, file); | fwrite(vch.data(), 1, nBytes, file); | ||||
fclose(file); | fclose(file); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |