From 61675c20d81a318e214a0e1a2cfc90c6c11527eb Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 29 Feb 2016 11:02:55 -0500 Subject: [PATCH] don't delete log file upon HUP --- Log.cpp | 8 +++++--- Log.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Log.cpp b/Log.cpp index 6391bcae..6bba1b62 100644 --- a/Log.cpp +++ b/Log.cpp @@ -44,10 +44,12 @@ void Log::Flush () m_LogStream->flush(); } -void Log::SetLogFile (const std::string& fullFilePath) +void Log::SetLogFile (const std::string& fullFilePath, bool truncate) { m_FullFilePath = fullFilePath; - auto logFile = std::make_shared (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); + auto mode = std::ofstream::out | std::ofstream::binary; + mode |= truncate ? std::ofstream::trunc : std::ofstream::app; + auto logFile = std::make_shared (fullFilePath, mode); if (logFile->is_open ()) { SetLogStream (logFile); @@ -59,7 +61,7 @@ void Log::ReopenLogFile () { if (m_FullFilePath.length () > 0) { - SetLogFile (m_FullFilePath); + SetLogFile (m_FullFilePath, false); // don't truncate LogPrint(eLogInfo, "Log: file ", m_FullFilePath, " reopen"); } } diff --git a/Log.h b/Log.h index 05bae7d9..5b07e2c9 100644 --- a/Log.h +++ b/Log.h @@ -38,7 +38,7 @@ class Log: public i2p::util::MsgQueue Log () { SetOnEmpty (std::bind (&Log::Flush, this)); }; ~Log () {}; - void SetLogFile (const std::string& fullFilePath); + void SetLogFile (const std::string& fullFilePath, bool truncate = true); void ReopenLogFile (); void SetLogLevel (const std::string& level); void SetLogStream (std::shared_ptr logStream);