To make logs more greppable, include the partition name in the log message.

This commit is contained in:
JoelKatz
2012-10-28 18:26:36 -07:00
parent 179b59bf3c
commit 3d650eb94f
2 changed files with 20 additions and 14 deletions

View File

@@ -41,14 +41,18 @@ std::vector< std::pair<std::string, std::string> > LogPartition::getSeverities()
Log::~Log()
{
std::string logMsg = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time());
if (!mPartitionName.empty())
logMsg += " " + mPartitionName + ":";
else
logMsg += " ";
switch (mSeverity)
{
case lsTRACE: logMsg += " TRAC "; break;
case lsDEBUG: logMsg += " DEBG "; break;
case lsINFO: logMsg += " INFO "; break;
case lsWARNING: logMsg += " WARN "; break;
case lsERROR: logMsg += " EROR "; break;
case lsFATAL: logMsg += " FATL "; break;
case lsTRACE: logMsg += "TRC "; break;
case lsDEBUG: logMsg += "DBG "; break;
case lsINFO: logMsg += "NFO "; break;
case lsWARNING: logMsg += "WRN "; break;
case lsERROR: logMsg += "ERR "; break;
case lsFATAL: logMsg += "FTL "; break;
case lsINVALID: assert(false); return;
}
logMsg += oss.str();

View File

@@ -17,10 +17,10 @@
#define SETUP_LOG() static LogPartition logPartition(__FILE__)
// Standard conditional log
#define cLog(x) if (!logPartition.doLog(x)) do {} while (0); else Log(x)
#define cLog(x) if (!logPartition.doLog(x)) do {} while (0); else Log(x, logPartition)
// Log only if an additional condition 'c' is true. Condition is not computed if not needed
#define tLog(c,x) if (!logPartition.doLog(x) || !(c)) do {} while(0); else Log(x)
#define tLog(c,x) if (!logPartition.doLog(x) || !(c)) do {} while(0); else Log(x, logPartition)
// Check if should log
#define sLog(x) (logPartition.doLog(x))
@@ -49,10 +49,8 @@ protected:
public:
LogPartition(const char *name);
bool doLog(LogSeverity s)
{
return s >= mMinSeverity;
}
bool doLog(LogSeverity s) { return s >= mMinSeverity; }
const std::string& getName() const { return mName; }
static bool setSeverity(const std::string& partition, LogSeverity severity);
static void setSeverity(LogSeverity severity);
@@ -70,8 +68,9 @@ protected:
static LogSeverity sMinSeverity;
static std::ofstream* outStream;
mutable std::ostringstream oss;
LogSeverity mSeverity;
mutable std::ostringstream oss;
LogSeverity mSeverity;
std::string mPartitionName;
static boost::filesystem::path *pathToLog;
static uint32 logRotateCounter;
@@ -80,6 +79,9 @@ public:
Log(LogSeverity s) : mSeverity(s)
{ ; }
Log(LogSeverity s, const LogPartition& p) : mSeverity(s), mPartitionName(p.getName())
{ ; }
~Log();
template<typename T> std::ostream& operator<<(const T& t) const