mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
To make logs more greppable, include the partition name in the log message.
This commit is contained in:
16
src/Log.cpp
16
src/Log.cpp
@@ -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();
|
||||
|
||||
18
src/Log.h
18
src/Log.h
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user