mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-13 19:37:51 +00:00
don't delete log file upon HUP
This commit is contained in:
parent
4aae878db8
commit
61675c20d8
8
Log.cpp
8
Log.cpp
@ -44,10 +44,12 @@ void Log::Flush ()
|
|||||||
m_LogStream->flush();
|
m_LogStream->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::SetLogFile (const std::string& fullFilePath)
|
void Log::SetLogFile (const std::string& fullFilePath, bool truncate)
|
||||||
{
|
{
|
||||||
m_FullFilePath = fullFilePath;
|
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 ())
|
if (logFile->is_open ())
|
||||||
{
|
{
|
||||||
SetLogStream (logFile);
|
SetLogStream (logFile);
|
||||||
@ -59,7 +61,7 @@ void Log::ReopenLogFile ()
|
|||||||
{
|
{
|
||||||
if (m_FullFilePath.length () > 0)
|
if (m_FullFilePath.length () > 0)
|
||||||
{
|
{
|
||||||
SetLogFile (m_FullFilePath);
|
SetLogFile (m_FullFilePath, false); // don't truncate
|
||||||
LogPrint(eLogInfo, "Log: file ", m_FullFilePath, " reopen");
|
LogPrint(eLogInfo, "Log: file ", m_FullFilePath, " reopen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
Log.h
2
Log.h
@ -38,7 +38,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
Log () { SetOnEmpty (std::bind (&Log::Flush, this)); };
|
Log () { SetOnEmpty (std::bind (&Log::Flush, this)); };
|
||||||
~Log () {};
|
~Log () {};
|
||||||
|
|
||||||
void SetLogFile (const std::string& fullFilePath);
|
void SetLogFile (const std::string& fullFilePath, bool truncate = true);
|
||||||
void ReopenLogFile ();
|
void ReopenLogFile ();
|
||||||
void SetLogLevel (const std::string& level);
|
void SetLogLevel (const std::string& level);
|
||||||
void SetLogStream (std::shared_ptr<std::ostream> logStream);
|
void SetLogStream (std::shared_ptr<std::ostream> logStream);
|
||||||
|
Loading…
Reference in New Issue
Block a user