diff options
Diffstat (limited to 'linden/indra/llcommon/llerror.h')
-rw-r--r-- | linden/indra/llcommon/llerror.h | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/linden/indra/llcommon/llerror.h b/linden/indra/llcommon/llerror.h index e1ace39..0a066bf 100644 --- a/linden/indra/llcommon/llerror.h +++ b/linden/indra/llcommon/llerror.h | |||
@@ -45,23 +45,23 @@ | |||
45 | 45 | ||
46 | Code can log messages with constuctions like this: | 46 | Code can log messages with constuctions like this: |
47 | 47 | ||
48 | llinfos << "request to fizzbip agent " << agent_id | 48 | LL_INFOS("StringTag") << "request to fizzbip agent " << agent_id |
49 | << " denied due to timeout" << llendl; | 49 | << " denied due to timeout" << LL_ENDL; |
50 | 50 | ||
51 | Messages can be logged to one of four increasing levels of concern, | 51 | Messages can be logged to one of four increasing levels of concern, |
52 | using one of four "streams": | 52 | using one of four "streams": |
53 | 53 | ||
54 | lldebugs - debug messages that are normally supressed | 54 | LL_DEBUGS("StringTag") - debug messages that are normally supressed |
55 | llinfos - informational messages that are normall shown | 55 | LL_INFOS("StringTag") - informational messages that are normall shown |
56 | llwarns - warning messages that singal a problem | 56 | LL_WARNS("StringTag") - warning messages that singal a problem |
57 | llerrs - error messages that are major, unrecoverable failures | 57 | LL_ERRS("StringTag") - error messages that are major, unrecoverable failures |
58 | 58 | ||
59 | The later (llerrs) automatically crashes the process after the message | 59 | The later (LL_ERRS("StringTag")) automatically crashes the process after the message |
60 | is logged. | 60 | is logged. |
61 | 61 | ||
62 | Note that these "streams" are actually #define magic. Rules for use: | 62 | Note that these "streams" are actually #define magic. Rules for use: |
63 | * they cannot be used as normal streams, only to start a message | 63 | * they cannot be used as normal streams, only to start a message |
64 | * messages written to them MUST be terminated with llendl | 64 | * messages written to them MUST be terminated with LL_ENDL |
65 | * between the opening and closing, the << operator is indeed | 65 | * between the opening and closing, the << operator is indeed |
66 | writing onto a std::ostream, so all conversions and stream | 66 | writing onto a std::ostream, so all conversions and stream |
67 | formating are available | 67 | formating are available |
@@ -85,7 +85,7 @@ | |||
85 | { | 85 | { |
86 | if (i > 100) | 86 | if (i > 100) |
87 | { | 87 | { |
88 | llwanrs << "called with a big value for i: " << i << llendl; | 88 | LL_WARNS("FooBarTag") << "called with a big value for i: " << i << LL_ENDL; |
89 | } | 89 | } |
90 | ... | 90 | ... |
91 | } | 91 | } |
@@ -100,7 +100,7 @@ | |||
100 | 100 | ||
101 | Lastly, logging is now very efficient in both compiled code and execution | 101 | Lastly, logging is now very efficient in both compiled code and execution |
102 | when skipped. There is no need to wrap messages, even debugging ones, in | 102 | when skipped. There is no need to wrap messages, even debugging ones, in |
103 | #ifdef _DEBUG constructs. lldebugs messages are compiled into all builds, | 103 | #ifdef _DEBUG constructs. LL_DEBUGS("StringTag") messages are compiled into all builds, |
104 | even release. Which means you can use them to help debug even when deployed | 104 | even release. Which means you can use them to help debug even when deployed |
105 | to a real grid. | 105 | to a real grid. |
106 | */ | 106 | */ |
@@ -144,7 +144,7 @@ namespace LLError | |||
144 | // intended for public use. | 144 | // intended for public use. |
145 | public: | 145 | public: |
146 | CallSite(ELevel, const char* file, int line, | 146 | CallSite(ELevel, const char* file, int line, |
147 | const std::type_info& class_info, const char* function); | 147 | const std::type_info& class_info, const char* function, const char* broadTag, const char* narrowTag, bool printOnce); |
148 | 148 | ||
149 | bool shouldLog() | 149 | bool shouldLog() |
150 | { return mCached ? mShouldLog : Log::shouldLog(*this); } | 150 | { return mCached ? mShouldLog : Log::shouldLog(*this); } |
@@ -156,9 +156,12 @@ namespace LLError | |||
156 | // these describe the call site and never change | 156 | // these describe the call site and never change |
157 | const ELevel mLevel; | 157 | const ELevel mLevel; |
158 | const char* const mFile; | 158 | const char* const mFile; |
159 | const int mLine; | 159 | const int mLine; |
160 | const std::type_info& mClassInfo; | 160 | const std::type_info& mClassInfo; |
161 | const char* const mFunction; | 161 | const char* const mFunction; |
162 | const char* const mBroadTag; | ||
163 | const char* const mNarrowTag; | ||
164 | const bool mPrintOnce; | ||
162 | 165 | ||
163 | // these implement a cache of the call to shouldLog() | 166 | // these implement a cache of the call to shouldLog() |
164 | bool mCached; | 167 | bool mCached; |
@@ -200,39 +203,66 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG; | |||
200 | See top of file for common usage. | 203 | See top of file for common usage. |
201 | */ | 204 | */ |
202 | 205 | ||
203 | #define lllog(level) \ | 206 | #define lllog(level, broadTag, narrowTag, once) \ |
204 | { \ | 207 | { \ |
205 | static LLError::CallSite _site( \ | 208 | static LLError::CallSite _site( \ |
206 | level, __FILE__, __LINE__, typeid(_LL_CLASS_TO_LOG), __FUNCTION__);\ | 209 | level, __FILE__, __LINE__, typeid(_LL_CLASS_TO_LOG), __FUNCTION__, broadTag, narrowTag, once);\ |
207 | if (_site.shouldLog()) \ | 210 | if (_site.shouldLog()) \ |
208 | { \ | 211 | { \ |
209 | std::ostringstream* _out = LLError::Log::out(); \ | 212 | std::ostringstream* _out = LLError::Log::out(); \ |
210 | (*_out) | 213 | (*_out) |
211 | 214 | ||
215 | // DEPRECATED: Don't call directly, use LL_ENDL instead, which actually looks like a macro | ||
212 | #define llendl \ | 216 | #define llendl \ |
213 | LLError::End(); \ | 217 | LLError::End(); \ |
214 | LLError::Log::flush(_out, _site); \ | 218 | LLError::Log::flush(_out, _site); \ |
215 | } \ | 219 | } \ |
216 | } | 220 | } |
217 | 221 | ||
218 | #define llinfos lllog(LLError::LEVEL_INFO) | 222 | // DEPRECATED: Use the new macros that allow tags and *look* like macros. |
219 | #define lldebugs lllog(LLError::LEVEL_DEBUG) | 223 | #define lldebugs lllog(LLError::LEVEL_DEBUG, NULL, NULL, false) |
220 | #define llwarns lllog(LLError::LEVEL_WARN) | 224 | #define llinfos lllog(LLError::LEVEL_INFO, NULL, NULL, false) |
221 | #define llerrs lllog(LLError::LEVEL_ERROR) | 225 | #define llwarns lllog(LLError::LEVEL_WARN, NULL, NULL, false) |
222 | 226 | #define llerrs lllog(LLError::LEVEL_ERROR, NULL, NULL, false) | |
223 | #define llcont (*_out) | 227 | #define llcont (*_out) |
228 | |||
229 | // NEW Macros for debugging, allow the passing of a string tag | ||
230 | |||
231 | // One Tag | ||
232 | #define LL_DEBUGS(broadTag) lllog(LLError::LEVEL_DEBUG, broadTag, NULL, false) | ||
233 | #define LL_INFOS(broadTag) lllog(LLError::LEVEL_INFO, broadTag, NULL, false) | ||
234 | #define LL_WARNS(broadTag) lllog(LLError::LEVEL_WARN, broadTag, NULL, false) | ||
235 | #define LL_ERRS(broadTag) lllog(LLError::LEVEL_ERROR, broadTag, NULL, false) | ||
236 | // Two Tags | ||
237 | #define LL_DEBUGS2(broadTag, narrowTag) lllog(LLError::LEVEL_DEBUG, broadTag, narrowTag, false) | ||
238 | #define LL_INFOS2(broadTag, narrowTag) lllog(LLError::LEVEL_INFO, broadTag, narrowTag, false) | ||
239 | #define LL_WARNS2(broadTag, narrowTag) lllog(LLError::LEVEL_WARN, broadTag, narrowTag, false) | ||
240 | #define LL_ERRS2(broadTag, narrowTag) lllog(LLError::LEVEL_ERROR, broadTag, narrowTag, false) | ||
241 | |||
242 | // Only print the log message once (good for warnings or infos that would otherwise | ||
243 | // spam the log file over and over, such as tighter loops). | ||
244 | #define LL_DEBUGS_ONCE(broadTag) lllog(LLError::LEVEL_DEBUG, broadTag, NULL, true) | ||
245 | #define LL_INFOS_ONCE(broadTag) lllog(LLError::LEVEL_INFO, broadTag, NULL, true) | ||
246 | #define LL_WARNS_ONCE(broadTag) lllog(LLError::LEVEL_WARN, broadTag, NULL, true) | ||
247 | #define LL_DEBUGS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_DEBUG, broadTag, narrowTag, true) | ||
248 | #define LL_INFOS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_INFO, broadTag, narrowTag, true) | ||
249 | #define LL_WARNS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_WARN, broadTag, narrowTag, true) | ||
250 | |||
251 | #define LL_ENDL llendl | ||
252 | #define LL_CONT (*_out) | ||
253 | |||
224 | /* | 254 | /* |
225 | Use this construct if you need to do computation in the middle of a | 255 | Use this construct if you need to do computation in the middle of a |
226 | message: | 256 | message: |
227 | 257 | ||
228 | llinfos << "the agent " << agend_id; | 258 | LL_INFOS("AgentGesture") << "the agent " << agend_id; |
229 | switch (f) | 259 | switch (f) |
230 | { | 260 | { |
231 | case FOP_SHRUGS: llcont << "shrugs"; break; | 261 | case FOP_SHRUGS: LL_CONT << "shrugs"; break; |
232 | case FOP_TAPS: llcont << "points at " << who; break; | 262 | case FOP_TAPS: LL_CONT << "points at " << who; break; |
233 | case FOP_SAYS: llcont << "says " << message; break; | 263 | case FOP_SAYS: LL_CONT << "says " << message; break; |
234 | } | 264 | } |
235 | llcont << " for " << t << " seconds" << llendl; | 265 | LL_CONT << " for " << t << " seconds" << LL_ENDL; |
236 | 266 | ||
237 | Such computation is done iff the message will be logged. | 267 | Such computation is done iff the message will be logged. |
238 | */ | 268 | */ |