Logger configuration & control output level
This commit is contained in:
@@ -23,6 +23,8 @@ void GraylogStream(std::string raw);
|
||||
|
||||
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logSQL, FLOG_MAX};
|
||||
|
||||
extern TLogLevel global_log_level;
|
||||
|
||||
void logfmt( TLogLevel level, const char * format, ... );
|
||||
|
||||
template <typename T>
|
||||
@@ -36,8 +38,10 @@ public:
|
||||
static TLogLevel& ReportingLevel();
|
||||
static std::string ToString(TLogLevel level);
|
||||
static TLogLevel FromString(const std::string& level);
|
||||
void SetReportingLevel(TLogLevel level = FLOG_MAX);
|
||||
protected:
|
||||
std::ostringstream os;
|
||||
TLogLevel currentLevel = FLOG_MAX;
|
||||
private:
|
||||
Log(const Log&);
|
||||
Log& operator =(const Log&);
|
||||
@@ -51,6 +55,7 @@ Log<T>::Log()
|
||||
template <typename T>
|
||||
std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
{
|
||||
currentLevel = level;
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level);
|
||||
os << " [" << getpid() << "]: ";
|
||||
@@ -61,18 +66,22 @@ std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
template <typename T>
|
||||
Log<T>::~Log()
|
||||
{
|
||||
if (currentLevel > global_log_level) {
|
||||
return; // We do not log messages greater than global log level!
|
||||
}
|
||||
|
||||
// Graylog
|
||||
//GraylogStream(os.str());
|
||||
GraylogStream(os.str());
|
||||
|
||||
os << std::endl;
|
||||
|
||||
T::Output(os.str());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TLogLevel& Log<T>::ReportingLevel()
|
||||
{
|
||||
static TLogLevel reportingLevel = FLOG_MAX;
|
||||
return reportingLevel;
|
||||
return global_log_level;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -87,8 +96,8 @@ TLogLevel Log<T>::FromString(const std::string& level)
|
||||
{
|
||||
if (level == "FLOG_MAX")
|
||||
return FLOG_MAX;
|
||||
if (level == "SQL")
|
||||
return logSQL;
|
||||
if (level == "SQL")
|
||||
return logSQL;
|
||||
if (level == "DEBUG4")
|
||||
return logDEBUG4;
|
||||
if (level == "DEBUG3")
|
||||
@@ -109,6 +118,12 @@ TLogLevel Log<T>::FromString(const std::string& level)
|
||||
return logINFO;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Log<T>::SetReportingLevel(TLogLevel level)
|
||||
{
|
||||
global_log_level = level;
|
||||
}
|
||||
|
||||
class Output2FILE
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define WRENCHBOARD_API_WRENCHBOARD_H
|
||||
|
||||
#include "vars.h"
|
||||
#include "clog.h"
|
||||
|
||||
// A very simple wrenchboard class
|
||||
class WrenchBoard {
|
||||
@@ -15,6 +16,7 @@ public:
|
||||
private:
|
||||
FILE* pFile;
|
||||
int db;
|
||||
int logFile;
|
||||
};
|
||||
|
||||
#endif /* WRENCHBOARD_API_WRENCHBOARD_H */
|
||||
|
||||
Reference in New Issue
Block a user