Browse Source

Stop writing to log if file exceeds 10 MB.

tags/v2.5.2
Andrew Belt 6 months ago
parent
commit
45113452eb
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      src/logger.cpp

+ 11
- 0
src/logger.cpp View File

@@ -15,6 +15,7 @@ std::string logPath;
static FILE* outputFile = NULL; static FILE* outputFile = NULL;
static std::mutex mutex; static std::mutex mutex;
static bool truncated = false; static bool truncated = false;
const static long maxSize = 10 * 1000 * 1000; // 10 MB




static bool fileEndsWith(FILE* file, std::string str) { static bool fileEndsWith(FILE* file, std::string str) {
@@ -97,7 +98,17 @@ static const int levelColors[] = {
static void logVa(Level level, const char* filename, int line, const char* func, const char* format, va_list args) { static void logVa(Level level, const char* filename, int line, const char* func, const char* format, va_list args) {
if (!outputFile) if (!outputFile)
return; return;

// Record logging time before calling OS functions
double nowTime = system::getTime(); double nowTime = system::getTime();

// Check if log size is full
if (outputFile != stderr) {
long pos = std::ftell(outputFile);
if (pos >= maxSize)
return;
}

std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);


if (outputFile == stderr) if (outputFile == stderr)


Loading…
Cancel
Save