mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
easylogging++: weed out most calls to allowed without locking
This commit is contained in:
parent
459beb50d4
commit
32b0560003
2 changed files with 26 additions and 15 deletions
37
external/easylogging++/easylogging++.cc
vendored
37
external/easylogging++/easylogging++.cc
vendored
|
@ -1969,7 +1969,7 @@ void RegisteredLoggers::unsafeFlushAll(void) {
|
||||||
|
|
||||||
// VRegistry
|
// VRegistry
|
||||||
|
|
||||||
VRegistry::VRegistry(base::type::VerboseLevel level, base::type::EnumType* pFlags) : m_level(level), m_pFlags(pFlags) {
|
VRegistry::VRegistry(base::type::VerboseLevel level, base::type::EnumType* pFlags) : m_level(level), m_pFlags(pFlags), m_lowest_priority(INT_MAX) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Sets verbose level. Accepted range is 0-9
|
/// @brief Sets verbose level. Accepted range is 0-9
|
||||||
|
@ -2053,14 +2053,30 @@ void VRegistry::setModules(const char* modules) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log levels are sorted in a weird way...
|
||||||
|
static int priority(Level level) {
|
||||||
|
if (level == Level::Fatal) return 0;
|
||||||
|
if (level == Level::Error) return 1;
|
||||||
|
if (level == Level::Warning) return 2;
|
||||||
|
if (level == Level::Info) return 3;
|
||||||
|
if (level == Level::Debug) return 4;
|
||||||
|
if (level == Level::Verbose) return 5;
|
||||||
|
if (level == Level::Trace) return 6;
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
void VRegistry::setCategories(const char* categories, bool clear) {
|
void VRegistry::setCategories(const char* categories, bool clear) {
|
||||||
base::threading::ScopedLock scopedLock(lock());
|
base::threading::ScopedLock scopedLock(lock());
|
||||||
auto insert = [&](std::stringstream& ss, Level level) {
|
auto insert = [&](std::stringstream& ss, Level level) {
|
||||||
m_categories.push_back(std::make_pair(ss.str(), level));
|
m_categories.push_back(std::make_pair(ss.str(), level));
|
||||||
m_cached_allowed_categories.clear();
|
m_cached_allowed_categories.clear();
|
||||||
|
int pri = priority(level);
|
||||||
|
if (pri > m_lowest_priority)
|
||||||
|
m_lowest_priority = pri;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
|
m_lowest_priority = 0;
|
||||||
m_categories.clear();
|
m_categories.clear();
|
||||||
m_cached_allowed_categories.clear();
|
m_cached_allowed_categories.clear();
|
||||||
m_categoriesString.clear();
|
m_categoriesString.clear();
|
||||||
|
@ -2117,23 +2133,14 @@ std::string VRegistry::getCategories() {
|
||||||
return m_categoriesString;
|
return m_categoriesString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log levels are sorted in a weird way...
|
|
||||||
static int priority(Level level) {
|
|
||||||
if (level == Level::Fatal) return 0;
|
|
||||||
if (level == Level::Error) return 1;
|
|
||||||
if (level == Level::Warning) return 2;
|
|
||||||
if (level == Level::Info) return 3;
|
|
||||||
if (level == Level::Debug) return 4;
|
|
||||||
if (level == Level::Verbose) return 5;
|
|
||||||
if (level == Level::Trace) return 6;
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VRegistry::allowed(Level level, const std::string &category) {
|
bool VRegistry::allowed(Level level, const std::string &category) {
|
||||||
|
const int pri = priority(level);
|
||||||
|
if (pri > m_lowest_priority)
|
||||||
|
return false;
|
||||||
base::threading::ScopedLock scopedLock(lock());
|
base::threading::ScopedLock scopedLock(lock());
|
||||||
const std::map<std::string, int>::const_iterator it = m_cached_allowed_categories.find(category);
|
const std::map<std::string, int>::const_iterator it = m_cached_allowed_categories.find(category);
|
||||||
if (it != m_cached_allowed_categories.end())
|
if (it != m_cached_allowed_categories.end())
|
||||||
return priority(level) <= it->second;
|
return pri <= it->second;
|
||||||
if (m_categories.empty()) {
|
if (m_categories.empty()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2142,7 +2149,7 @@ bool VRegistry::allowed(Level level, const std::string &category) {
|
||||||
if (base::utils::Str::wildCardMatch(category.c_str(), it->first.c_str())) {
|
if (base::utils::Str::wildCardMatch(category.c_str(), it->first.c_str())) {
|
||||||
const int p = priority(it->second);
|
const int p = priority(it->second);
|
||||||
m_cached_allowed_categories.insert(std::make_pair(category, p));
|
m_cached_allowed_categories.insert(std::make_pair(category, p));
|
||||||
return priority(level) <= p;
|
return pri <= p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_cached_allowed_categories.insert(std::make_pair(category, -1));
|
m_cached_allowed_categories.insert(std::make_pair(category, -1));
|
||||||
|
|
4
external/easylogging++/easylogging++.h
vendored
4
external/easylogging++/easylogging++.h
vendored
|
@ -359,6 +359,7 @@ ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStre
|
||||||
#if defined(ELPP_SYSLOG)
|
#if defined(ELPP_SYSLOG)
|
||||||
# include <syslog.h>
|
# include <syslog.h>
|
||||||
#endif // defined(ELPP_SYSLOG)
|
#endif // defined(ELPP_SYSLOG)
|
||||||
|
#include <climits>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -406,6 +407,7 @@ ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStre
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <atomic>
|
||||||
#if ELPP_THREADING_ENABLED
|
#if ELPP_THREADING_ENABLED
|
||||||
# if ELPP_USE_STD_THREADING
|
# if ELPP_USE_STD_THREADING
|
||||||
# include <mutex>
|
# include <mutex>
|
||||||
|
@ -2451,6 +2453,7 @@ class VRegistry : base::NoCopy, public base::threading::ThreadSafe {
|
||||||
base::threading::ScopedLock scopedLock(lock());
|
base::threading::ScopedLock scopedLock(lock());
|
||||||
m_categories.clear();
|
m_categories.clear();
|
||||||
m_cached_allowed_categories.clear();
|
m_cached_allowed_categories.clear();
|
||||||
|
m_lowest_priority = INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clearModules(void) {
|
inline void clearModules(void) {
|
||||||
|
@ -2495,6 +2498,7 @@ class VRegistry : base::NoCopy, public base::threading::ThreadSafe {
|
||||||
std::map<std::string, int> m_cached_allowed_categories;
|
std::map<std::string, int> m_cached_allowed_categories;
|
||||||
std::string m_categoriesString;
|
std::string m_categoriesString;
|
||||||
std::string m_filenameCommonPrefix;
|
std::string m_filenameCommonPrefix;
|
||||||
|
std::atomic<int> m_lowest_priority;
|
||||||
};
|
};
|
||||||
} // namespace base
|
} // namespace base
|
||||||
class LogMessage {
|
class LogMessage {
|
||||||
|
|
Loading…
Reference in a new issue