diff options
Diffstat (limited to 'indra/llcommon/llerror.cpp')
-rw-r--r-- | indra/llcommon/llerror.cpp | 356 |
1 files changed, 158 insertions, 198 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 40eb7d9bac..335a0995fe 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -132,8 +132,6 @@ namespace { mFile.sync_with_stdio(false); } } - mWantsTime = true; - mWantsTags = true; } ~RecordToFile() @@ -175,7 +173,7 @@ namespace { public: RecordToStderr(bool timestamp) : mUseANSI(ANSI_PROBE) { - mWantsTime = timestamp; + this->showMultiline(true); } virtual bool enabled() override @@ -241,7 +239,13 @@ namespace { class RecordToFixedBuffer : public LLError::Recorder { public: - RecordToFixedBuffer(LLLineBuffer* buffer) : mBuffer(buffer) { } + RecordToFixedBuffer(LLLineBuffer* buffer) + : mBuffer(buffer) + { + this->showMultiline(true); + this->showTags(false); + this->showLocation(false); + } virtual bool enabled() override { @@ -263,7 +267,11 @@ namespace { { public: RecordToWinDebug() - {} + { + this->showMultiline(true); + this->showTags(false); + this->showLocation(false); + } virtual bool enabled() override { @@ -382,15 +390,22 @@ namespace { llifstream file(filename().c_str()); - if (file.is_open()) + if (!file.is_open()) { - LLSDSerialize::fromXML(configuration, file); + LL_WARNS() << filename() << " failed to open file; not changing configuration" << LL_ENDL; + return false; + } + + if (LLSDSerialize::fromXML(configuration, file) == LLSDParser::PARSE_FAILURE) + { + LL_WARNS() << filename() << " parcing error; not changing configuration" << LL_ENDL; + return false; } - if (configuration.isUndefined()) + if (configuration.isUndefined() || !configuration.isMap() || configuration.emptyMap()) { - LL_WARNS() << filename() << " missing, ill-formed," - " or simply undefined; not changing configuration" + LL_WARNS() << filename() << " missing, ill-formed, or simply undefined" + " content; not changing configuration" << LL_ENDL; return false; } @@ -412,6 +427,7 @@ namespace public: std::ostringstream messageStream; bool messageStreamInUse; + std::string mFatalMessage; void addCallSite(LLError::CallSite&); void invalidateCallSites(); @@ -454,8 +470,6 @@ namespace LLError public: virtual ~SettingsConfig(); - bool mPrintLocation; - LLError::ELevel mDefaultLevel; bool mLogAlwaysFlush; @@ -500,7 +514,6 @@ namespace LLError SettingsConfig::SettingsConfig() : LLRefCount(), - mPrintLocation(false), mDefaultLevel(LLError::LEVEL_DEBUG), mLogAlwaysFlush(true), mEnabledLogTypesMask(255), @@ -706,23 +719,22 @@ namespace LLError commonInit(user_dir, app_dir, log_to_stderr); } - void setPrintLocation(bool print) + void setFatalFunction(const FatalFunction& f) { SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig(); - s->mPrintLocation = print; + s->mCrashFunction = f; } - void setFatalFunction(const FatalFunction& f) + FatalFunction getFatalFunction() { SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig(); - s->mCrashFunction = f; + return s->mCrashFunction; } - FatalFunction getFatalFunction() - { - SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig(); - return s->mCrashFunction; - } + std::string getFatalMessage() + { + return Globals::getInstance()->mFatalMessage; + } void setTimeFunction(TimeFunction f) { @@ -845,7 +857,6 @@ namespace LLError s->mTagLevelMap.clear(); s->mUniqueLogMessages.clear(); - setPrintLocation(config["print-location"]); setDefaultLevel(decodeLevel(config["default-level"])); if (config.has("log-always-flush")) { @@ -856,19 +867,24 @@ namespace LLError setEnabledLogTypesMask(config["enabled-log-types-mask"].asInteger()); } - LLSD sets = config["settings"]; - LLSD::array_const_iterator a, end; - for (a = sets.beginArray(), end = sets.endArray(); a != end; ++a) - { - const LLSD& entry = *a; - - ELevel level = decodeLevel(entry["level"]); - - setLevels(s->mFunctionLevelMap, entry["functions"], level); - setLevels(s->mClassLevelMap, entry["classes"], level); - setLevels(s->mFileLevelMap, entry["files"], level); - setLevels(s->mTagLevelMap, entry["tags"], level); - } + if (config.has("settings") && config["settings"].isArray()) + { + LLSD sets = config["settings"]; + LLSD::array_const_iterator a, end; + for (a = sets.beginArray(), end = sets.endArray(); a != end; ++a) + { + const LLSD& entry = *a; + if (entry.isMap() && !entry.emptyMap()) + { + ELevel level = decodeLevel(entry["level"]); + + setLevels(s->mFunctionLevelMap, entry["functions"], level); + setLevels(s->mClassLevelMap, entry["classes"], level); + setLevels(s->mFileLevelMap, entry["files"], level); + setLevels(s->mTagLevelMap, entry["tags"], level); + } + } + } } } @@ -876,11 +892,12 @@ namespace LLError namespace LLError { Recorder::Recorder() - : mWantsTime(false), - mWantsTags(false), - mWantsLevel(true), - mWantsLocation(false), - mWantsFunctionName(true) + : mWantsTime(true) + , mWantsTags(true) + , mWantsLevel(true) + , mWantsLocation(true) + , mWantsFunctionName(true) + , mWantsMultiline(false) { } @@ -917,6 +934,42 @@ namespace LLError return mWantsFunctionName; } + // virtual + bool Recorder::wantsMultiline() + { + return mWantsMultiline; + } + + void Recorder::showTime(bool show) + { + mWantsTime = show; + } + + void Recorder::showTags(bool show) + { + mWantsTags = show; + } + + void Recorder::showLevel(bool show) + { + mWantsLevel = show; + } + + void Recorder::showLocation(bool show) + { + mWantsLocation = show; + } + + void Recorder::showFunctionName(bool show) + { + mWantsFunctionName = show; + } + + void Recorder::showMultiline(bool show) + { + mWantsMultiline = show; + } + void addRecorder(RecorderPtr recorder) { if (!recorder) @@ -949,17 +1002,15 @@ namespace LLError s->mFileRecorder.reset(); s->mFileRecorderFileName.clear(); - if (file_name.empty()) + if (!file_name.empty()) { - return; - } - - RecorderPtr recordToFile(new RecordToFile(file_name)); - if (boost::dynamic_pointer_cast<RecordToFile>(recordToFile)->okay()) - { - s->mFileRecorderFileName = file_name; - s->mFileRecorder = recordToFile; - addRecorder(recordToFile); + RecorderPtr recordToFile(new RecordToFile(file_name)); + if (boost::dynamic_pointer_cast<RecordToFile>(recordToFile)->okay()) + { + s->mFileRecorderFileName = file_name; + s->mFileRecorder = recordToFile; + addRecorder(recordToFile); + } } } @@ -970,14 +1021,12 @@ namespace LLError removeRecorder(s->mFixedBufferRecorder); s->mFixedBufferRecorder.reset(); - if (!fixedBuffer) + if (fixedBuffer) { - return; - } - - RecorderPtr recordToFixedBuffer(new RecordToFixedBuffer(fixedBuffer)); - s->mFixedBufferRecorder = recordToFixedBuffer; - addRecorder(recordToFixedBuffer); + RecorderPtr recordToFixedBuffer(new RecordToFixedBuffer(fixedBuffer)); + s->mFixedBufferRecorder = recordToFixedBuffer; + addRecorder(recordToFixedBuffer); + } } std::string logFileName() @@ -989,8 +1038,9 @@ namespace LLError namespace { - void addEscapedMessage(std::ostream& out, const std::string& message) + std::string escapedMessageLines(const std::string& message) { + std::ostringstream out; size_t written_out = 0; size_t all_content = message.length(); size_t escape_char_index; // always relative to start of message @@ -1026,13 +1076,16 @@ namespace // write whatever was left out << message.substr(written_out, std::string::npos); } + return out.str(); } - void writeToRecorders(const LLError::CallSite& site, const std::string& escaped_message) + void writeToRecorders(const LLError::CallSite& site, const std::string& message) { LLError::ELevel level = site.mLevel; LLError::SettingsConfigPtr s = LLError::Settings::getInstance()->getSettingsConfig(); - + + std::string escaped_message; + for (Recorders::const_iterator i = s->mRecorders.begin(); i != s->mRecorders.end(); ++i) @@ -1064,7 +1117,7 @@ namespace } message_stream << " "; - if (r->wantsLocation() || level == LLError::LEVEL_ERROR || s->mPrintLocation) + if (r->wantsLocation() || level == LLError::LEVEL_ERROR) { message_stream << site.mLocationString; } @@ -1076,7 +1129,18 @@ namespace } message_stream << " : "; - message_stream << escaped_message; + if (r->wantsMultiline()) + { + message_stream << message; + } + else + { + if (escaped_message.empty()) + { + escaped_message = escapedMessageLines(message); + } + message_stream << escaped_message; + } r->recordMessage(level, message_stream.str()); } @@ -1084,6 +1148,9 @@ namespace } namespace { + LLMutex gLogMutex; + LLMutex gCallStacksLogMutex; + bool checkLevelMap(const LevelMap& map, const std::string& key, LLError::ELevel& level) { @@ -1123,56 +1190,6 @@ namespace { } return found_level; } - - class LogLock - { - public: - LogLock(); - ~LogLock(); - bool ok() const { return mOK; } - private: - bool mLocked; - bool mOK; - }; - - LogLock::LogLock() - : mLocked(false), mOK(false) - { - if (!gLogMutexp) - { - mOK = true; - return; - } - - const int MAX_RETRIES = 5; - for (int attempts = 0; attempts < MAX_RETRIES; ++attempts) - { - apr_status_t s = apr_thread_mutex_trylock(gLogMutexp); - if (!APR_STATUS_IS_EBUSY(s)) - { - mLocked = true; - mOK = true; - return; - } - - ms_sleep(1); - //apr_thread_yield(); - // Just yielding won't necessarily work, I had problems with - // this on Linux - doug 12/02/04 - } - - // We're hosed, we can't get the mutex. Blah. - std::cerr << "LogLock::LogLock: failed to get mutex for log" - << std::endl; - } - - LogLock::~LogLock() - { - if (mLocked) - { - apr_thread_mutex_unlock(gLogMutexp); - } - } } namespace LLError @@ -1180,8 +1197,8 @@ namespace LLError bool Log::shouldLog(CallSite& site) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex, 5); + if (!lock.isLocked()) { return false; } @@ -1231,11 +1248,11 @@ namespace LLError std::ostringstream* Log::out() { - LogLock lock; + LLMutexTrylock lock(&gLogMutex,5); // If we hit a logging request very late during shutdown processing, // when either of the relevant LLSingletons has already been deleted, // DO NOT resurrect them. - if (lock.ok() && ! (Settings::wasDeleted() || Globals::wasDeleted())) + if (lock.isLocked() && ! (Settings::wasDeleted() || Globals::wasDeleted())) { Globals* g = Globals::getInstance(); @@ -1251,8 +1268,8 @@ namespace LLError void Log::flush(std::ostringstream* out, char* message) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex,5); + if (!lock.isLocked()) { return; } @@ -1291,8 +1308,8 @@ namespace LLError void Log::flush(std::ostringstream* out, const CallSite& site) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex,5); + if (!lock.isLocked()) { return; } @@ -1320,10 +1337,11 @@ namespace LLError delete out; } - std::ostringstream message_stream; if (site.mPrintOnce) { + std::ostringstream message_stream; + std::map<std::string, unsigned int>::iterator messageIter = s->mUniqueLogMessages.find(message); if (messageIter != s->mUniqueLogMessages.end()) { @@ -1343,15 +1361,19 @@ namespace LLError message_stream << "ONCE: "; s->mUniqueLogMessages[message] = 1; } + message_stream << message; + message = message_stream.str(); } - addEscapedMessage(message_stream, message); + writeToRecorders(site, message); - writeToRecorders(site, message_stream.str()); - - if (site.mLevel == LEVEL_ERROR && s->mCrashFunction) + if (site.mLevel == LEVEL_ERROR) { - s->mCrashFunction(message_stream.str()); + g->mFatalMessage = message; + if (s->mCrashFunction) + { + s->mCrashFunction(message); + } } } } @@ -1457,69 +1479,6 @@ namespace LLError char** LLCallStacks::sBuffer = NULL ; S32 LLCallStacks::sIndex = 0 ; -#define SINGLE_THREADED 1 - - class CallStacksLogLock - { - public: - CallStacksLogLock(); - ~CallStacksLogLock(); - -#if SINGLE_THREADED - bool ok() const { return true; } -#else - bool ok() const { return mOK; } - private: - bool mLocked; - bool mOK; -#endif - }; - -#if SINGLE_THREADED - CallStacksLogLock::CallStacksLogLock() - { - } - CallStacksLogLock::~CallStacksLogLock() - { - } -#else - CallStacksLogLock::CallStacksLogLock() - : mLocked(false), mOK(false) - { - if (!gCallStacksLogMutexp) - { - mOK = true; - return; - } - - const int MAX_RETRIES = 5; - for (int attempts = 0; attempts < MAX_RETRIES; ++attempts) - { - apr_status_t s = apr_thread_mutex_trylock(gCallStacksLogMutexp); - if (!APR_STATUS_IS_EBUSY(s)) - { - mLocked = true; - mOK = true; - return; - } - - ms_sleep(1); - } - - // We're hosed, we can't get the mutex. Blah. - std::cerr << "CallStacksLogLock::CallStacksLogLock: failed to get mutex for log" - << std::endl; - } - - CallStacksLogLock::~CallStacksLogLock() - { - if (mLocked) - { - apr_thread_mutex_unlock(gCallStacksLogMutexp); - } - } -#endif - //static void LLCallStacks::allocateStackBuffer() { @@ -1548,8 +1507,8 @@ namespace LLError //static void LLCallStacks::push(const char* function, const int line) { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1583,8 +1542,8 @@ namespace LLError //static void LLCallStacks::end(std::ostringstream* _out) { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1605,8 +1564,8 @@ namespace LLError //static void LLCallStacks::print() { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1643,8 +1602,8 @@ namespace LLError bool debugLoggingEnabled(const std::string& tag) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex, 5); + if (!lock.isLocked()) { return false; } @@ -1656,3 +1615,4 @@ bool debugLoggingEnabled(const std::string& tag) } + |