summaryrefslogtreecommitdiff
path: root/indra/llcommon/llerrorcontrol.h
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2021-05-21 20:31:53 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2021-05-21 20:31:53 +0300
commit2922c593160f81d19f39d80fc84a25c2a0e0d8aa (patch)
tree7b5c5aa2889cb2e7d746d54a6ec9778cc7c77480 /indra/llcommon/llerrorcontrol.h
parent646cde231d72fb217c6d34cd95d941a24544ca3a (diff)
parent24501dfa0ee3fd6f5755deb1bc5261cd297a2bc7 (diff)
Merge branch 'sl-10297' into DRTVWR-516-maint
Diffstat (limited to 'indra/llcommon/llerrorcontrol.h')
-rw-r--r--indra/llcommon/llerrorcontrol.h57
1 files changed, 46 insertions, 11 deletions
diff --git a/indra/llcommon/llerrorcontrol.h b/indra/llcommon/llerrorcontrol.h
index 25786d5457..e87bb7bf35 100644
--- a/indra/llcommon/llerrorcontrol.h
+++ b/indra/llcommon/llerrorcontrol.h
@@ -94,14 +94,16 @@ namespace LLError
*/
typedef boost::function<void(const std::string&)> FatalFunction;
- LL_COMMON_API void crashAndLoop(const std::string& message);
- // Default fatal function: access null pointer and loops forever
LL_COMMON_API void setFatalFunction(const FatalFunction&);
- // The fatal function will be called when an message of LEVEL_ERROR
+ // The fatal function will be called after an message of LEVEL_ERROR
// is logged. Note: supressing a LEVEL_ERROR message from being logged
// (by, for example, setting a class level to LEVEL_NONE), will keep
- // the that message from causing the fatal funciton to be invoked.
+ // that message from causing the fatal function to be invoked.
+ // The passed FatalFunction will be the LAST log function called
+ // before LL_ERRS crashes its caller. A FatalFunction can throw an
+ // exception, or call exit(), to bypass the crash. It MUST disrupt the
+ // flow of control because no caller expects LL_ERRS to return.
LL_COMMON_API FatalFunction getFatalFunction();
// Retrieve the previously-set FatalFunction
@@ -147,14 +149,14 @@ namespace LLError
virtual void recordMessage(LLError::ELevel, const std::string& message) = 0;
// use the level for better display, not for filtering
- virtual bool enabled() { return true; }
+ virtual bool enabled() { return true; }
bool wantsTime();
bool wantsTags();
bool wantsLevel();
bool wantsLocation();
bool wantsFunctionName();
- bool wantsMultiline();
+ bool wantsMultiline();
void showTime(bool show);
void showTags(bool show);
@@ -165,15 +167,35 @@ namespace LLError
protected:
bool mWantsTime;
- bool mWantsTags;
- bool mWantsLevel;
- bool mWantsLocation;
- bool mWantsFunctionName;
- bool mWantsMultiline;
+ bool mWantsTags;
+ bool mWantsLevel;
+ bool mWantsLocation;
+ bool mWantsFunctionName;
+ bool mWantsMultiline;
};
typedef boost::shared_ptr<Recorder> RecorderPtr;
+ /**
+ * Instantiate GenericRecorder with a callable(level, message) to get
+ * control on every log message without having to code an explicit
+ * Recorder subclass.
+ */
+ template <typename CALLABLE>
+ class GenericRecorder: public Recorder
+ {
+ public:
+ GenericRecorder(const CALLABLE& callable):
+ mCallable(callable)
+ {}
+ void recordMessage(LLError::ELevel level, const std::string& message) override
+ {
+ mCallable(level, message);
+ }
+ private:
+ CALLABLE mCallable;
+ };
+
/**
* @NOTE: addRecorder() and removeRecorder() uses the boost::shared_ptr to allow for shared ownership
* while still ensuring that the allocated memory is eventually freed
@@ -181,6 +203,19 @@ namespace LLError
LL_COMMON_API void addRecorder(RecorderPtr);
LL_COMMON_API void removeRecorder(RecorderPtr);
// each error message is passed to each recorder via recordMessage()
+ /**
+ * Call addGenericRecorder() with a callable(level, message) to get
+ * control on every log message without having to code an explicit
+ * Recorder subclass. Save the returned RecorderPtr if you later want to
+ * call removeRecorder().
+ */
+ template <typename CALLABLE>
+ RecorderPtr addGenericRecorder(const CALLABLE& callable)
+ {
+ RecorderPtr ptr{ new GenericRecorder<CALLABLE>(callable) };
+ addRecorder(ptr);
+ return ptr;
+ }
LL_COMMON_API void logToFile(const std::string& filename);
LL_COMMON_API void logToStderr();