mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 03:37:49 +02:00
pass instance of std::ostream for logging from API
This commit is contained in:
parent
b7d1b74ffa
commit
bb05bcf39f
4 changed files with 39 additions and 18 deletions
25
Log.cpp
25
Log.cpp
|
@ -20,19 +20,24 @@ void LogMsg::Process()
|
|||
|
||||
void Log::Flush ()
|
||||
{
|
||||
if (m_LogFile)
|
||||
m_LogFile->flush();
|
||||
if (m_LogStream)
|
||||
m_LogStream->flush();
|
||||
}
|
||||
|
||||
void Log::SetLogFile (const std::string& fullFilePath)
|
||||
{
|
||||
if (m_LogFile) delete m_LogFile;
|
||||
m_LogFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||
if (m_LogFile->is_open ())
|
||||
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
||||
else
|
||||
auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||
if (logFile->is_open ())
|
||||
{
|
||||
delete m_LogFile;
|
||||
m_LogFile = nullptr;
|
||||
}
|
||||
SetLogStream (logFile);
|
||||
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
||||
}
|
||||
else
|
||||
delete logFile;
|
||||
}
|
||||
|
||||
void Log::SetLogStream (std::ostream * logStream)
|
||||
{
|
||||
if (m_LogStream) delete m_LogStream;
|
||||
m_LogStream = logStream;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue