mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
#355. reopen log file by SIGHUP
This commit is contained in:
parent
7ca1cfab1a
commit
98d5e0b56d
@ -17,9 +17,9 @@ void handle_signal(int sig)
|
|||||||
switch (sig)
|
switch (sig)
|
||||||
{
|
{
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
LogPrint(eLogInfo, "Daemon: Got SIGHUP, doing nothing");
|
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening log...");
|
||||||
// TODO:
|
ReopenLogFile ();
|
||||||
break;
|
break;
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
|
11
Log.cpp
11
Log.cpp
@ -46,6 +46,7 @@ void Log::Flush ()
|
|||||||
|
|
||||||
void Log::SetLogFile (const std::string& fullFilePath)
|
void Log::SetLogFile (const std::string& fullFilePath)
|
||||||
{
|
{
|
||||||
|
m_FullFilePath = fullFilePath;
|
||||||
auto logFile = std::make_shared<std::ofstream> (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
auto logFile = std::make_shared<std::ofstream> (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||||
if (logFile->is_open ())
|
if (logFile->is_open ())
|
||||||
{
|
{
|
||||||
@ -54,6 +55,16 @@ void Log::SetLogFile (const std::string& fullFilePath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Log::ReopenLogFile ()
|
||||||
|
{
|
||||||
|
if (m_FullFilePath.length () > 0)
|
||||||
|
{
|
||||||
|
SetLogFile (m_FullFilePath);
|
||||||
|
LogPrint(eLogInfo, "Log: file ", m_FullFilePath, " reopen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Log::SetLogLevel (const std::string& level)
|
void Log::SetLogLevel (const std::string& level)
|
||||||
{
|
{
|
||||||
if (level == "error") { m_MinLevel = eLogError; }
|
if (level == "error") { m_MinLevel = eLogError; }
|
||||||
|
8
Log.h
8
Log.h
@ -39,6 +39,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
~Log () {};
|
~Log () {};
|
||||||
|
|
||||||
void SetLogFile (const std::string& fullFilePath);
|
void SetLogFile (const std::string& fullFilePath);
|
||||||
|
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);
|
||||||
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; };
|
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; };
|
||||||
@ -51,6 +52,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::string m_FullFilePath; // empty if stream
|
||||||
std::shared_ptr<std::ostream> m_LogStream;
|
std::shared_ptr<std::ostream> m_LogStream;
|
||||||
enum LogLevel m_MinLevel;
|
enum LogLevel m_MinLevel;
|
||||||
std::string m_Timestamp;
|
std::string m_Timestamp;
|
||||||
@ -102,6 +104,12 @@ inline void SetLogLevel (const std::string& level)
|
|||||||
g_Log->SetLogLevel(level);
|
g_Log->SetLogLevel(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void ReopenLogFile ()
|
||||||
|
{
|
||||||
|
if (g_Log)
|
||||||
|
g_Log->ReopenLogFile ();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename TValue>
|
template<typename TValue>
|
||||||
void LogPrint (std::stringstream& s, TValue arg)
|
void LogPrint (std::stringstream& s, TValue arg)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user