Fix log chattiness. Add a new configuration parameter "debug_logfile"

This commit is contained in:
JoelKatz
2012-06-18 20:05:12 -07:00
parent a3daa061d3
commit a1523fcb06
6 changed files with 44 additions and 8 deletions

View File

@@ -1,15 +1,15 @@
#include "Log.h"
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
boost::recursive_mutex Log::sLock;
#ifdef DEBUG
LogSeverity Log::sMinSeverity = lsTRACE;
#else
LogSeverity Log::sMinSeverity = lsINFO;
#endif
LogSeverity Log::sMinSeverity = lsWARNING;
std::ofstream* Log::outStream = NULL;
Log::~Log()
{
@@ -26,9 +26,9 @@ Log::~Log()
logMsg += oss.str();
boost::recursive_mutex::scoped_lock sl(sLock);
if (mSeverity >= sMinSeverity)
{
std::cerr << logMsg << std::endl;
}
if (outStream != NULL)
(*outStream) << logMsg << std::endl;
}
void Log::setMinSeverity(LogSeverity s)
@@ -36,3 +36,20 @@ void Log::setMinSeverity(LogSeverity s)
boost::recursive_mutex::scoped_lock sl(sLock);
sMinSeverity = s;
}
void Log::setLogFile(boost::filesystem::path path)
{
std::ofstream* newStream = new std::ofstream(path.c_str(), std::fstream::app);
if (!newStream->good())
{
delete newStream;
newStream = NULL;
}
boost::recursive_mutex::scoped_lock sl(sLock);
if (outStream != NULL)
delete outStream;
outStream = newStream;
if (outStream)
Log(lsINFO) << "Starting up";
}