summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2020-10-26 21:04:10 +0200
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2020-10-26 21:04:10 +0200
commit95e724f3deb856b0b69a3850ceb938c81d1f0321 (patch)
treedf8e21a352a5c66cb8dbf8e88f1ad9799c80b390
parent802b52f3044dfaaec3406d654c091d626955f569 (diff)
SL-14004 Coalesce viewer's LLError::Settings and Globals
-rw-r--r--indra/llcommon/llerror.cpp265
1 files changed, 122 insertions, 143 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index f876b8ee4a..781c41f3de 100644
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -435,6 +435,60 @@ namespace
typedef std::vector<LLError::RecorderPtr> Recorders;
typedef std::vector<LLError::CallSite*> CallSiteVector;
+ class SettingsConfig : public LLRefCount
+ {
+ friend class Globals;
+
+ public:
+ virtual ~SettingsConfig();
+
+ LLError::ELevel mDefaultLevel;
+
+ bool mLogAlwaysFlush;
+
+ U32 mEnabledLogTypesMask;
+
+ LevelMap mFunctionLevelMap;
+ LevelMap mClassLevelMap;
+ LevelMap mFileLevelMap;
+ LevelMap mTagLevelMap;
+ std::map<std::string, unsigned int> mUniqueLogMessages;
+
+ LLError::FatalFunction mCrashFunction;
+ LLError::TimeFunction mTimeFunction;
+
+ Recorders mRecorders;
+
+ int mShouldLogCallCounter;
+
+ private:
+ SettingsConfig();
+ };
+
+ typedef LLPointer<SettingsConfig> SettingsConfigPtr;
+
+ SettingsConfig::SettingsConfig()
+ : LLRefCount(),
+ mDefaultLevel(LLError::LEVEL_DEBUG),
+ mLogAlwaysFlush(true),
+ mEnabledLogTypesMask(255),
+ mFunctionLevelMap(),
+ mClassLevelMap(),
+ mFileLevelMap(),
+ mTagLevelMap(),
+ mUniqueLogMessages(),
+ mCrashFunction(NULL),
+ mTimeFunction(NULL),
+ mRecorders(),
+ mShouldLogCallCounter(0)
+ {
+ }
+
+ SettingsConfig::~SettingsConfig()
+ {
+ mRecorders.clear();
+ }
+
class Globals
{
public:
@@ -449,14 +503,21 @@ namespace
void addCallSite(LLError::CallSite&);
void invalidateCallSites();
+ SettingsConfigPtr getSettingsConfig();
+
+ void resetSettingsConfig();
+ LLError::SettingsStoragePtr saveAndResetSettingsConfig();
+ void restore(LLError::SettingsStoragePtr pSettingsStorage);
private:
CallSiteVector callSites;
+ SettingsConfigPtr mSettingsConfig;
};
Globals::Globals()
: messageStream(),
messageStreamInUse(false),
- callSites()
+ callSites(),
+ mSettingsConfig(new SettingsConfig())
{
}
@@ -486,120 +547,31 @@ namespace
callSites.clear();
}
-}
-
-namespace LLError
-{
- class SettingsConfig : public LLRefCount
- {
- friend class Settings;
-
- public:
- virtual ~SettingsConfig();
-
- LLError::ELevel mDefaultLevel;
-
- bool mLogAlwaysFlush;
-
- U32 mEnabledLogTypesMask;
-
- LevelMap mFunctionLevelMap;
- LevelMap mClassLevelMap;
- LevelMap mFileLevelMap;
- LevelMap mTagLevelMap;
- std::map<std::string, unsigned int> mUniqueLogMessages;
-
- LLError::FatalFunction mCrashFunction;
- LLError::TimeFunction mTimeFunction;
-
- Recorders mRecorders;
-
- int mShouldLogCallCounter;
-
- private:
- SettingsConfig();
- };
-
- typedef LLPointer<SettingsConfig> SettingsConfigPtr;
-
- class Settings
- {
- public:
- static Settings* getInstance();
- protected:
- Settings();
- public:
- SettingsConfigPtr getSettingsConfig();
-
- void reset();
- SettingsStoragePtr saveAndReset();
- void restore(SettingsStoragePtr pSettingsStorage);
-
- private:
- SettingsConfigPtr mSettingsConfig;
- };
-
- SettingsConfig::SettingsConfig()
- : LLRefCount(),
- mDefaultLevel(LLError::LEVEL_DEBUG),
- mLogAlwaysFlush(true),
- mEnabledLogTypesMask(255),
- mFunctionLevelMap(),
- mClassLevelMap(),
- mFileLevelMap(),
- mTagLevelMap(),
- mUniqueLogMessages(),
- mCrashFunction(NULL),
- mTimeFunction(NULL),
- mRecorders(),
- mShouldLogCallCounter(0)
- {
- }
- SettingsConfig::~SettingsConfig()
- {
- mRecorders.clear();
- }
-
- Settings::Settings():
- mSettingsConfig(new SettingsConfig())
- {
- }
-
- Settings* Settings::getInstance()
+ SettingsConfigPtr Globals::getSettingsConfig()
{
- // According to C++11 Function-Local Initialization
- // of static variables is supposed to be thread safe
- // without risk of deadlocks.
- static Settings inst;
-
- return &inst;
+ return mSettingsConfig;
}
- SettingsConfigPtr Settings::getSettingsConfig()
- {
- return mSettingsConfig;
- }
-
- void Settings::reset()
- {
- Globals::getInstance()->invalidateCallSites();
- mSettingsConfig = new SettingsConfig();
- }
+ void Globals::resetSettingsConfig()
+ {
+ invalidateCallSites();
+ mSettingsConfig = new SettingsConfig();
+ }
- SettingsStoragePtr Settings::saveAndReset()
- {
- SettingsStoragePtr oldSettingsConfig(mSettingsConfig.get());
- reset();
- return oldSettingsConfig;
- }
+ LLError::SettingsStoragePtr Globals::saveAndResetSettingsConfig()
+ {
+ LLError::SettingsStoragePtr oldSettingsConfig(mSettingsConfig.get());
+ resetSettingsConfig();
+ return oldSettingsConfig;
+ }
- void Settings::restore(SettingsStoragePtr pSettingsStorage)
- {
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr newSettingsConfig(dynamic_cast<SettingsConfig *>(pSettingsStorage.get()));
- mSettingsConfig = newSettingsConfig;
- }
+ void Globals::restore(LLError::SettingsStoragePtr pSettingsStorage)
+ {
+ invalidateCallSites();
+ SettingsConfigPtr newSettingsConfig(dynamic_cast<SettingsConfig *>(pSettingsStorage.get()));
+ mSettingsConfig = newSettingsConfig;
+ }
}
namespace LLError
@@ -723,7 +695,7 @@ namespace
void commonInit(const std::string& user_dir, const std::string& app_dir, bool log_to_stderr = true)
{
- LLError::Settings::getInstance()->reset();
+ Globals::getInstance()->resetSettingsConfig();
LLError::setDefaultLevel(LLError::LEVEL_INFO);
LLError::setAlwaysFlush(true);
@@ -765,13 +737,13 @@ namespace LLError
void setFatalFunction(const FatalFunction& f)
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mCrashFunction = f;
}
FatalFunction getFatalFunction()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
return s->mCrashFunction;
}
@@ -782,72 +754,77 @@ namespace LLError
void setTimeFunction(TimeFunction f)
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mTimeFunction = f;
}
void setDefaultLevel(ELevel level)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mDefaultLevel = level;
}
ELevel getDefaultLevel()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
return s->mDefaultLevel;
}
void setAlwaysFlush(bool flush)
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mLogAlwaysFlush = flush;
}
bool getAlwaysFlush()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
return s->mLogAlwaysFlush;
}
void setEnabledLogTypesMask(U32 mask)
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mEnabledLogTypesMask = mask;
}
U32 getEnabledLogTypesMask()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
return s->mEnabledLogTypesMask;
}
void setFunctionLevel(const std::string& function_name, ELevel level)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mFunctionLevelMap[function_name] = level;
}
void setClassLevel(const std::string& class_name, ELevel level)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mClassLevelMap[class_name] = level;
}
void setFileLevel(const std::string& file_name, ELevel level)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mFileLevelMap[file_name] = level;
}
void setTagLevel(const std::string& tag_name, ELevel level)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mTagLevelMap[tag_name] = level;
}
@@ -892,8 +869,9 @@ namespace LLError
{
void configure(const LLSD& config)
{
- Globals::getInstance()->invalidateCallSites();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ g->invalidateCallSites();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mFunctionLevelMap.clear();
s->mClassLevelMap.clear();
@@ -1020,7 +998,7 @@ namespace LLError
{
return;
}
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mRecorders.push_back(recorder);
}
@@ -1030,7 +1008,7 @@ namespace LLError
{
return;
}
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mRecorders.erase(std::remove(s->mRecorders.begin(), s->mRecorders.end(), recorder),
s->mRecorders.end());
}
@@ -1046,7 +1024,7 @@ namespace LLError
std::pair<boost::shared_ptr<RECORDER>, Recorders::iterator>
findRecorderPos()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
// Since we promise to return an iterator, use a classic iterator
// loop.
auto end{s->mRecorders.end()};
@@ -1089,7 +1067,7 @@ namespace LLError
auto found = findRecorderPos<RECORDER>();
if (found.first)
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
s->mRecorders.erase(found.second);
}
return bool(found.first);
@@ -1187,7 +1165,7 @@ namespace
void writeToRecorders(const LLError::CallSite& site, const std::string& message)
{
LLError::ELevel level = site.mLevel;
- LLError::SettingsConfigPtr s = LLError::Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
std::string escaped_message;
@@ -1325,7 +1303,8 @@ namespace LLError
return false;
}
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ Globals *g = Globals::getInstance();
+ SettingsConfigPtr s = g->getSettingsConfig();
s->mShouldLogCallCounter++;
@@ -1355,7 +1334,7 @@ namespace LLError
: false);
site.mCached = true;
- Globals::getInstance()->addCallSite(site);
+ g->addCallSite(site);
return site.mShouldLog = site.mLevel >= compareLevel;
}
@@ -1419,7 +1398,7 @@ namespace LLError
}
Globals* g = Globals::getInstance();
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = g->getSettingsConfig();
std::string message = out->str();
if (out == &g->messageStream)
@@ -1478,12 +1457,12 @@ namespace LLError
{
SettingsStoragePtr saveAndResetSettings()
{
- return Settings::getInstance()->saveAndReset();
+ return Globals::getInstance()->saveAndResetSettingsConfig();
}
void restoreSettings(SettingsStoragePtr pSettingsStorage)
{
- return Settings::getInstance()->restore(pSettingsStorage);
+ return Globals::getInstance()->restore(pSettingsStorage);
}
std::string removePrefix(std::string& s, const std::string& p)
@@ -1529,7 +1508,7 @@ namespace LLError
int shouldLogCallCount()
{
- SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig();
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
return s->mShouldLogCallCounter;
}
@@ -1707,8 +1686,8 @@ bool debugLoggingEnabled(const std::string& tag)
{
return false;
}
-
- LLError::SettingsConfigPtr s = LLError::Settings::getInstance()->getSettingsConfig();
+
+ SettingsConfigPtr s = Globals::getInstance()->getSettingsConfig();
LLError::ELevel level = LLError::LEVEL_DEBUG;
bool res = checkLevelMap(s->mTagLevelMap, tag, level);
return res;