diff --git a/src/Log.cpp b/src/Log.cpp index 948552cbf9..74904c6a3d 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -13,6 +13,8 @@ std::ofstream* Log::outStream = NULL; boost::filesystem::path *Log::pathToLog = NULL; uint32 Log::logRotateCounter = 0; +LogPartition* LogPartition::headLog = NULL; + Log::~Log() { std::string logMsg = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); @@ -79,6 +81,7 @@ void Log::setMinSeverity(LogSeverity s) { boost::recursive_mutex::scoped_lock sl(sLock); sMinSeverity = s; + LogPartition::setSeverity(s); } void Log::setLogFile(boost::filesystem::path path) @@ -99,3 +102,19 @@ void Log::setLogFile(boost::filesystem::path path) pathToLog = new boost::filesystem::path(path); } + +void LogPartition::setSeverity(const char *partition, LogSeverity severity) +{ + for (LogPartition *p = headLog; p != NULL; p = p->mNextLog) + if (p->mName == partition) + { + p->mMinSeverity = severity; + return; + } +} + +void LogPartition::setSeverity(LogSeverity severity) +{ + for (LogPartition *p = headLog; p != NULL; p = p->mNextLog) + p->mMinSeverity = severity; +} diff --git a/src/Log.h b/src/Log.h index fd3db13fd3..409a8e476f 100644 --- a/src/Log.h +++ b/src/Log.h @@ -2,6 +2,8 @@ #define __LOG__ #include +#include +#include #include #include @@ -10,7 +12,9 @@ #include "../json/json.h" #include "types.h" -#include + +#define SETUP_LOG() static LogPartition logPartition(__FILE__) +#define cLog(x) if (logPartition.doLog(x)) Log(x) enum LogSeverity { @@ -22,6 +26,32 @@ enum LogSeverity lsFATAL = 5 }; +class LogPartition +{ +protected: + static LogPartition* headLog; + + LogPartition* mNextLog; + LogSeverity mMinSeverity; + std::string mName; + +public: + LogPartition(const char *name) : mNextLog(headLog), mMinSeverity(lsWARNING) + { + const char *ptr = strrchr(name, '/'); + mName = (ptr == NULL) ? name : ptr; + headLog = this; + } + + bool doLog(enum LogSeverity s) + { + return s >= mMinSeverity; + } + + static void setSeverity(const char *partition, LogSeverity severity); + static void setSeverity(LogSeverity severity); +}; + class Log { private: