diff --git a/Log.cpp b/Log.cpp index 12f8860..408f6a6 100644 --- a/Log.cpp +++ b/Log.cpp @@ -102,13 +102,13 @@ private: class FileOutput : public Output { public: - FileOutput(const std::string& filename, Level lvl_max) - : Output(lvl_max), filename(filename), ofs(filename, std::ofstream::out | std::ofstream::app) {} + FileOutput(const std::string& filename, Level lvl_max, bool truncate) + : Output(lvl_max), filename(filename), ofs(filename, truncate ? std::ostream::trunc : std::ostream::app) {} - FileOutput(const std::string& filename, Level lvl_min, Level lvl_max) + FileOutput(const std::string& filename, Level lvl_min, Level lvl_max, bool truncate) : Output(lvl_max), filename(filename), - ofs(filename, std::ofstream::out | std::ofstream::app), + ofs(filename, truncate ? std::ostream::trunc : std::ostream::app), lvl_min(lvl_min) {} private: @@ -182,12 +182,12 @@ void stop() { outputs.clear(); } -void addLogfile(const std::string& filename, Level max) { - outputs.push_back(new FileOutput(filename, max)); +void addLogfile(const std::string& filename, Level max, bool truncate) { + outputs.push_back(new FileOutput(filename, max, truncate)); } -void addLogfile(const std::string& filename, Level min, Level max) { - outputs.push_back(new FileOutput(filename, min, max)); +void addLogfile(const std::string& filename, Level min, Level max, bool truncate) { + outputs.push_back(new FileOutput(filename, min, max, truncate)); } void setConsoleLogLevel(Level lvl) { diff --git a/Log.h b/Log.h index 0107bf4..ea7b06d 100644 --- a/Log.h +++ b/Log.h @@ -15,8 +15,8 @@ void init(); // close all output streams void stop(); -void addLogfile(const std::string& filename, Level max); -void addLogfile(const std::string& filename, Level min, Level max); +void addLogfile(const std::string& filename, Level max, bool truncate = false); +void addLogfile(const std::string& filename, Level min, Level max, bool truncate = false); void setConsoleLogLevel(Level lvl); void setColoredOutput(bool enabled);