Skip to content
/ i2pd Public
forked from PurpleI2P/i2pd

Commit

Permalink
don't delete log file upon HUP
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Feb 29, 2016
1 parent 4aae878 commit 61675c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::ofstream> (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<std::ofstream> (fullFilePath, mode);
if (logFile->is_open ())
{
SetLogStream (logFile);
Expand All @@ -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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
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<std::ostream> logStream);
Expand Down

0 comments on commit 61675c2

Please sign in to comment.