aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defaultsettings.cpp1
-rw-r--r--src/log.cpp26
-rw-r--r--src/log.h2
-rw-r--r--src/main.cpp9
4 files changed, 27 insertions, 11 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 7756bc45d..0c51610c9 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -385,6 +385,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("ignore_world_load_errors", "false");
settings->setDefault("remote_media", "");
settings->setDefault("debug_log_level", "action");
+ settings->setDefault("debug_log_size_max", "50");
settings->setDefault("emergequeue_limit_total", "512");
settings->setDefault("emergequeue_limit_diskonly", "64");
settings->setDefault("emergequeue_limit_generate", "64");
diff --git a/src/log.cpp b/src/log.cpp
index c84a847a5..30344b4df 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -310,16 +310,32 @@ void Logger::logToOutputs(LogLevel lev, const std::string &combined,
//// *LogOutput methods
////
-void FileLogOutput::open(const std::string &filename)
+void FileLogOutput::setFile(const std::string &filename, s64 file_size_max)
{
- m_stream.open(filename.c_str(), std::ios::app | std::ios::ate);
+ // Only move debug.txt if there is a valid maximum file size
+ bool is_too_large = false;
+ if (file_size_max > 0) {
+ std::ifstream ifile(filename, std::ios::binary | std::ios::ate);
+ is_too_large = ifile.tellg() > file_size_max;
+ ifile.close();
+ }
+
+ if (is_too_large) {
+ std::string filename_secondary = filename + ".1";
+ actionstream << "The log file grew too big; it is moved to " <<
+ filename_secondary << std::endl;
+ remove(filename_secondary.c_str());
+ rename(filename.c_str(), filename_secondary.c_str());
+ }
+ m_stream.open(filename, std::ios::app | std::ios::ate);
+
if (!m_stream.good())
throw FileNotGoodException("Failed to open log file " +
filename + ": " + strerror(errno));
m_stream << "\n\n"
- "-------------" << std::endl
- << " Separator" << std::endl
- << "-------------\n" << std::endl;
+ "-------------" << std::endl <<
+ " Separator" << std::endl <<
+ "-------------\n" << std::endl;
}
diff --git a/src/log.h b/src/log.h
index 1427d1364..6350d8a86 100644
--- a/src/log.h
+++ b/src/log.h
@@ -165,7 +165,7 @@ private:
class FileLogOutput : public ICombinedLogOutput {
public:
- void open(const std::string &filename);
+ void setFile(const std::string &filename, s64 file_size_max);
void logRaw(LogLevel lev, const std::string &line)
{
diff --git a/src/main.cpp b/src/main.cpp
index bd83f9638..6323fa50e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
} else {
errorstream << "Invalid --worldlist value: "
<< cmd_args.get("worldlist") << std::endl;
- return 1;
+ return 1;
}
return 0;
}
@@ -426,7 +426,7 @@ static bool setup_log_params(const Settings &cmd_args)
} else {
errorstream << "Invalid color mode: " << color_mode << std::endl;
return false;
- }
+ }
}
// If trace is enabled, enable logging of certain things
@@ -580,9 +580,8 @@ static void init_log_streams(const Settings &cmd_args)
"using maximum." << std::endl;
}
- verbosestream << "log_filename = " << log_filename << std::endl;
-
- file_log_output.open(log_filename);
+ file_log_output.setFile(log_filename,
+ g_settings->getU64("debug_log_size_max") * 1000000);
g_logger.addOutputMaxLevel(&file_log_output, log_level);
}