Merge pull request #4950

68f045de easylogging++: check allowed categories before logging (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2019-01-06 20:38:10 +02:00
commit 3ce7977389
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 36 additions and 8 deletions

View file

@ -38,14 +38,21 @@
#define MAX_LOG_FILE_SIZE 104850000 // 100 MB - 7600 bytes #define MAX_LOG_FILE_SIZE 104850000 // 100 MB - 7600 bytes
#define MAX_LOG_FILES 50 #define MAX_LOG_FILES 50
#define MCFATAL(cat,x) CLOG(FATAL,cat) << x #define MCLOG_TYPE(level, cat, type, x) do { \
#define MCERROR(cat,x) CLOG(ERROR,cat) << x if (ELPP->vRegistry()->allowed(level, cat)) { \
#define MCWARNING(cat,x) CLOG(WARNING,cat) << x el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
#define MCINFO(cat,x) CLOG(INFO,cat) << x } \
#define MCDEBUG(cat,x) CLOG(DEBUG,cat) << x } while (0)
#define MCTRACE(cat,x) CLOG(TRACE,cat) << x
#define MCLOG(level,cat,x) ELPP_WRITE_LOG(el::base::Writer, level, el::base::DispatchAction::NormalLog, cat) << x #define MCLOG(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::NormalLog, x)
#define MCLOG_FILE(level,cat,x) ELPP_WRITE_LOG(el::base::Writer, level, el::base::DispatchAction::FileOnlyLog, cat) << x #define MCLOG_FILE(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::FileOnlyLog, x)
#define MCFATAL(cat,x) MCLOG(el::Level::Fatal,cat, x)
#define MCERROR(cat,x) MCLOG(el::Level::Error,cat, x)
#define MCWARNING(cat,x) MCLOG(el::Level::Warning,cat, x)
#define MCINFO(cat,x) MCLOG(el::Level::Info,cat, x)
#define MCDEBUG(cat,x) MCLOG(el::Level::Debug,cat, x)
#define MCTRACE(cat,x) MCLOG(el::Level::Trace,cat, x)
#define MCLOG_COLOR(level,cat,color,x) MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m") #define MCLOG_COLOR(level,cat,color,x) MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")
#define MCLOG_RED(level,cat,x) MCLOG_COLOR(level,cat,"31",x) #define MCLOG_RED(level,cat,x) MCLOG_COLOR(level,cat,"31",x)

View file

@ -2693,6 +2693,12 @@ Writer& Writer::construct(int count, const char* loggerIds, ...) {
return *this; return *this;
} }
Writer& Writer::construct(const char *loggerId) {
initializeLogger(ELPP->registeredLoggers()->get(loggerId, ELPP->hasFlag(LoggingFlag::CreateLoggerAutomatically)));
m_messageBuilder.initialize(m_logger);
return *this;
}
void Writer::initializeLogger(const std::string& loggerId, bool lookup, bool needLock) { void Writer::initializeLogger(const std::string& loggerId, bool lookup, bool needLock) {
if (lookup) { if (lookup) {
m_logger = ELPP->registeredLoggers()->get(loggerId, ELPP->hasFlag(LoggingFlag::CreateLoggerAutomatically)); m_logger = ELPP->registeredLoggers()->get(loggerId, ELPP->hasFlag(LoggingFlag::CreateLoggerAutomatically));
@ -2721,6 +2727,19 @@ void Writer::initializeLogger(const std::string& loggerId, bool lookup, bool nee
} }
} }
void Writer::initializeLogger(Logger *logger, bool needLock) {
m_logger = logger;
if (m_logger == nullptr) {
m_proceed = false;
} else {
if (needLock) {
m_logger->acquireLock(); // This should not be unlocked by checking m_proceed because
// m_proceed can be changed by lines below
}
m_proceed = true;
}
}
void Writer::processDispatch() { void Writer::processDispatch() {
#if ELPP_LOGGING_ENABLED #if ELPP_LOGGING_ENABLED
if (ELPP->hasFlag(LoggingFlag::MultiLoggerSupport)) { if (ELPP->hasFlag(LoggingFlag::MultiLoggerSupport)) {

View file

@ -3290,6 +3290,7 @@ class Writer : base::NoCopy {
Writer& construct(Logger* logger, bool needLock = true); Writer& construct(Logger* logger, bool needLock = true);
Writer& construct(int count, const char* loggerIds, ...); Writer& construct(int count, const char* loggerIds, ...);
Writer& construct(const char *loggerId);
protected: protected:
LogMessage* m_msg; LogMessage* m_msg;
Level m_level; Level m_level;
@ -3305,6 +3306,7 @@ class Writer : base::NoCopy {
friend class el::Helpers; friend class el::Helpers;
void initializeLogger(const std::string& loggerId, bool lookup = true, bool needLock = true); void initializeLogger(const std::string& loggerId, bool lookup = true, bool needLock = true);
void initializeLogger(Logger *logger, bool needLock = true);
void processDispatch(); void processDispatch();
void triggerDispatch(void); void triggerDispatch(void);
}; };