00001 00033 #ifndef LL_LLERRORCONTROL_H 00034 #define LL_LLERRORCONTROL_H 00035 00036 #include "llerror.h" 00037 00038 #include <string> 00039 00040 class LLFixedBuffer; 00041 class LLSD; 00042 00043 /* 00044 This is the part of the LLError namespace that manages the messages 00045 produced by the logging. The logging support is defined in llerror.h. 00046 Most files do not need to include this. 00047 00048 These implementations are in llerror.cpp. 00049 */ 00050 00051 00052 namespace LLError 00053 { 00054 void initForServer(const std::string& identity); 00055 // resets all logging settings to defaults needed by server processes 00056 // logs to stderr, syslog, and windows debug log 00057 // the identity string is used for in the syslog 00058 00059 void initForApplication(const std::string& dir); 00060 // resets all logging settings to defaults needed by applicaitons 00061 // logs to stderr and windows debug log 00062 // sets up log configuration from the file logcontrol.xml in dir 00063 00064 00065 /* 00066 Settings that control what is logged. 00067 Setting a level means log messages at that level or above. 00068 */ 00069 00070 void setPrintLocation(bool); 00071 void setDefaultLevel(LLError::ELevel); 00072 void setFunctionLevel(const std::string& function_name, LLError::ELevel); 00073 void setClassLevel(const std::string& class_name, LLError::ELevel); 00074 void setFileLevel(const std::string& file_name, LLError::ELevel); 00075 00076 void configure(const LLSD&); 00077 // the LLSD can configure all of the settings 00078 // usually read automatically from the live errorlog.xml file 00079 00080 00081 /* 00082 Control functions. 00083 */ 00084 00085 typedef void (*FatalFunction)(const std::string& message); 00086 void crashAndLoop(const std::string& message); 00087 // Default fatal funtion: divides by zero and loops forever 00088 00089 void setFatalFunction(FatalFunction); 00090 // The fatal function will be called when an message of LEVEL_ERROR 00091 // is logged. Note: supressing a LEVEL_ERROR message from being logged 00092 // (by, for example, setting a class level to LEVEL_NONE), will keep 00093 // the that message from causing the fatal funciton to be invoked. 00094 00095 typedef std::string (*TimeFunction)(); 00096 std::string utcTime(); 00097 00098 void setTimeFunction(TimeFunction); 00099 // The function is use to return the current time, formatted for 00100 // display by those error recorders that want the time included. 00101 00102 00103 00104 class Recorder 00105 { 00106 // An object that handles the actual output or error messages. 00107 public: 00108 virtual ~Recorder(); 00109 00110 virtual void recordMessage(LLError::ELevel, const std::string& message) = 0; 00111 // use the level for better display, not for filtering 00112 00113 virtual bool wantsTime(); // default returns false 00114 // override and return true if the recorder wants the time string 00115 // included in the text of the message 00116 }; 00117 00118 void addRecorder(Recorder*); 00119 void removeRecorder(Recorder*); 00120 // each error message is passed to each recorder via recordMessage() 00121 00122 void logToFile(const std::string& filename); 00123 void logToFixedBuffer(LLFixedBuffer*); 00124 // Utilities to add recorders for logging to a file or a fixed buffer 00125 // A second call to the same function will remove the logger added 00126 // with the first. 00127 // Passing the empty string or NULL to just removes any prior. 00128 std::string logFileName(); 00129 // returns name of current logging file, empty string if none 00130 00131 00132 /* 00133 Utilities for use by the unit tests of LLError itself. 00134 */ 00135 00136 class Settings; 00137 Settings* saveAndResetSettings(); 00138 void restoreSettings(Settings *); 00139 00140 std::string abbreviateFile(const std::string& filePath); 00141 int shouldLogCallCount(); 00142 00143 }; 00144 00145 #endif // LL_LLERRORCONTROL_H 00146