#include <log.h>
Inheritance diagram for NLMISC::CLog:
log_howto
Nevrax France
Definition at line 54 of file log.h.
Public Types | |
enum | TLogType { LOG_NO = 0, LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_STAT, LOG_ASSERT, LOG_UNKNOWN } |
Public Member Functions | |
void | addDisplayer (IDisplayer *displayer, bool bypassFilter=false) |
void | addNegativeFilter (const char *filterstr) |
Adds a negative filter. Tells the logger to discard the lines that contain filterstr. | |
void | addPositiveFilter (const char *filterstr) |
Adds a positive filter. Tells the logger to log only the lines that contain filterstr. | |
bool | attached (IDisplayer *displayer) const |
Returns true if the specified displayer is attached to the log object. | |
CLog (TLogType logType=LOG_NO) | |
void | display (const char *format,...) |
Display a string in decorated form to all attached displayers. Call setPosition() before. Releases the mutex. | |
void | displayFilter (CLog &log) |
Displays the list of filter into a log. | |
void | displayNL (const char *format,...) |
Display a string in decorated and final new line form to all attached displayers. Call setPosition() before. Releases the mutex. | |
void | displayRaw (const char *format,...) |
Display a string (and nothing more) to all attached displayers. Call setPosition() before. Releases the mutex. | |
void | displayRawNL (const char *format,...) |
Display a string with a final new line to all attached displayers. Call setPosition() before. Releases the mutex. | |
void | forceDisplayRaw (const char *format,...) |
IDisplayer * | getDisplayer (const char *displayerName) |
Return the first displayer selected by his name. | |
bool | noDisplayer () const |
Returns true if no displayer is attached. | |
void | removeDisplayer (const char *displayerName) |
Remove a displayer using his name. | |
void | removeDisplayer (IDisplayer *displayer) |
Remove a displayer. If the displayer doesn't work in a specific time, you could remove it. | |
void | removeFilter (const char *filterstr=NULL) |
Removes a filter by name (in both filters). | |
void | resetFilters () |
Reset both filters. | |
void | setPosition (sint line, char *fileName) |
If !noDisplayer(), sets line and file parameters, and enters the mutex. If !noDisplayer(), don't forget to call display...() after, to release the mutex. | |
Static Public Member Functions | |
void | setDefaultProcessName () |
Find the process name if nobody call setProcessName before. | |
void | setProcessName (const std::string &processName) |
Set the name of the process. | |
Protected Types | |
typedef std::list< IDisplayer * > | CDisplayers |
Protected Member Functions | |
void | displayRawString (const char *str) |
Display a Raw string to all attached displayers. | |
void | displayString (const char *str) |
Display a string in decorated form to all attached displayers. | |
bool | passFilter (const char *filter) |
Returns true if the string must be logged, according to the current filter. | |
void | unsetPosition () |
Symetric to setPosition(). Automatically called by display...(). Do not call if noDisplayer(). | |
Protected Attributes | |
CDisplayers | _BypassFilterDisplayers |
CDisplayers | _Displayers |
char * | _FileName |
sint | _Line |
TLogType | _LogType |
CMutex | _Mutex |
std::list< std::string > | _NegativeFilter |
"Discard" filter | |
std::list< std::string > | _PositiveFilter |
"Crop" filter | |
uint32 | _PosSet |
TDisplayInfo | TempArgs |
std::string | TempString |
Static Protected Attributes | |
std::string * | _ProcessName = NULL |
|
|
|
Definition at line 57 of file log.h.
00057 { LOG_NO=0, LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_STAT, LOG_ASSERT, LOG_UNKNOWN } TLogType; |
|
Definition at line 51 of file log.cpp. References LOG, NLMISC::toString(), and uint.
|
|
Add a new displayer in the log. You have to create the displayer, remove it and delete it when you have finish with it. For example, in a 3dDisplayer, you can add the displayer when you want, and the displayer displays the string if the 3d screen is available and do nothing otherwise. In this case, if you want, you could leave the displayer all the time. Definition at line 115 of file log.cpp. References _BypassFilterDisplayers, _Displayers, and nlwarning. Referenced by NLMISC::initDebug2(), NLNET::IService::main(), NLNET::serviceGetView(), and NLNET::updateAdmin().
00116 { 00117 if (displayer == NULL) 00118 { 00119 // Can't nlwarning because recursive call 00120 printf ("Trying to add a NULL displayer\n"); 00121 return; 00122 } 00123 00124 if (bypassFilter) 00125 { 00126 CDisplayers::iterator idi = std::find (_BypassFilterDisplayers.begin (), _BypassFilterDisplayers.end (), displayer); 00127 if (idi == _BypassFilterDisplayers.end ()) 00128 { 00129 _BypassFilterDisplayers.push_back (displayer); 00130 } 00131 else 00132 { 00133 nlwarning ("LOG: Couldn't add the displayer, it was already added"); 00134 } 00135 } 00136 else 00137 { 00138 CDisplayers::iterator idi = std::find (_Displayers.begin (), _Displayers.end (), displayer); 00139 if (idi == _Displayers.end ()) 00140 { 00141 _Displayers.push_back (displayer); 00142 } 00143 else 00144 { 00145 nlwarning ("LOG: Couldn't add the displayer, it was already added"); 00146 } 00147 } 00148 } |
|
Adds a negative filter. Tells the logger to discard the lines that contain filterstr.
Definition at line 593 of file log.cpp. References _NegativeFilter. Referenced by NLNET::cbLogFilter(), and NLMISC::NLMISC_COMMAND().
00594 { 00595 //displayNL ("CLog::addNegativeFilter('%s')", filterstr); 00596 _NegativeFilter.push_back( filterstr ); 00597 } |
|
Adds a positive filter. Tells the logger to log only the lines that contain filterstr.
Definition at line 587 of file log.cpp. References _PositiveFilter. Referenced by NLMISC::NLMISC_COMMAND().
00588 { 00589 //displayNL ("CLog::addPositiveFilter('%s')", filterstr); 00590 _PositiveFilter.push_back( filterstr ); 00591 } |
|
Returns true if the specified displayer is attached to the log object.
Definition at line 235 of file log.cpp. References _BypassFilterDisplayers, and _Displayers.
00236 { 00237 return (find( _Displayers.begin(), _Displayers.end(), displayer ) != _Displayers.end()) || 00238 (find( _BypassFilterDisplayers.begin(), _BypassFilterDisplayers.end(), displayer ) != _BypassFilterDisplayers.end()); 00239 } |
|
Display a string in decorated form to all attached displayers. Call setPosition() before. Releases the mutex.
Definition at line 348 of file log.cpp. References format, and NLMISC_CONVERT_VARGS. Referenced by NLMISC::CBufFIFO::display().
00350 { 00351 if ( noDisplayer() ) 00352 { 00353 return; 00354 } 00355 00356 char *str; 00357 NLMISC_CONVERT_VARGS (str, format, 256/*NLMISC::MaxCStringSize*/); 00358 00359 displayString (str); 00360 } |
|
Displays the list of filter into a log.
Definition at line 572 of file log.cpp. References _NegativeFilter, _PositiveFilter, and displayNL(). Referenced by NLMISC::NLMISC_COMMAND().
00573 { 00574 std::list<std::string>::iterator it; 00575 log.displayNL ("Positive Filter(s):"); 00576 for (it = _PositiveFilter.begin (); it != _PositiveFilter.end (); it++) 00577 { 00578 log.displayNL ("'%s'", (*it).c_str()); 00579 } 00580 log.displayNL ("Negative Filter(s):"); 00581 for (it = _NegativeFilter.begin (); it != _NegativeFilter.end (); it++) 00582 { 00583 log.displayNL ("'%s'", (*it).c_str()); 00584 } 00585 } |
|
|
Display a string (and nothing more) to all attached displayers. Call setPosition() before. Releases the mutex.
Definition at line 467 of file log.cpp. References format, and NLMISC_CONVERT_VARGS. Referenced by NLNET::cleanRequest(), and NLMISC::CConfigFile::display().
00469 { 00470 if ( noDisplayer() ) 00471 { 00472 return; 00473 } 00474 00475 char *str; 00476 NLMISC_CONVERT_VARGS (str, format, 256/*NLMISC::MaxCStringSize*/); 00477 00478 displayRawString(str); 00479 } |
|
|
Display a Raw string to all attached displayers.
Definition at line 362 of file log.cpp. References _BypassFilterDisplayers, _Displayers, NLMISC::CLog::TDisplayInfo::CallstackAndLog, NLMISC::CLog::TDisplayInfo::Date, NLMISC::CLog::TDisplayInfo::Filename, NLMISC::getCallStackAndLog(), NLMISC::CLog::TDisplayInfo::Line, LOG_ASSERT, LOG_ERROR, NLMISC::CLog::TDisplayInfo::LogType, passFilter(), NLMISC::CLog::TDisplayInfo::ProcessName, setDefaultProcessName(), TempArgs, TempString, NLMISC::CLog::TDisplayInfo::ThreadId, and unsetPosition().
00363 { 00364 const char *disp = NULL; 00365 TDisplayInfo localargs, *args = NULL; 00366 00367 setDefaultProcessName (); 00368 00369 if(strchr(str,'\n') == NULL) 00370 { 00371 if (TempString.empty()) 00372 { 00373 localargs.Date = 0; 00374 localargs.LogType = CLog::LOG_NO; 00375 localargs.ProcessName = ""; 00376 localargs.ThreadId = 0; 00377 localargs.Filename = NULL; 00378 localargs.Line = -1; 00379 localargs.CallstackAndLog = ""; 00380 00381 TempString = str; 00382 } 00383 else 00384 { 00385 TempString += str; 00386 } 00387 return; 00388 } 00389 else 00390 { 00391 if (TempString.empty()) 00392 { 00393 localargs.Date = 0; 00394 localargs.LogType = CLog::LOG_NO; 00395 localargs.ProcessName = ""; 00396 localargs.ThreadId = 0; 00397 localargs.Filename = NULL; 00398 localargs.Line = -1; 00399 localargs.CallstackAndLog = ""; 00400 00401 disp = str; 00402 args = &localargs; 00403 } 00404 else 00405 { 00406 TempString += str; 00407 disp = TempString.c_str(); 00408 args = &TempArgs; 00409 } 00410 } 00411 00412 // send to all bypass filter displayers 00413 for (CDisplayers::iterator idi=_BypassFilterDisplayers.begin(); idi!=_BypassFilterDisplayers.end(); idi++ ) 00414 { 00415 (*idi)->display( *args, disp ); 00416 } 00417 00418 // get the log at the last minute to be sure to have everything 00419 if(args->LogType == LOG_ERROR || args->LogType == LOG_ASSERT) 00420 { 00421 getCallStackAndLog (args->CallstackAndLog, 4); 00422 } 00423 00424 if ( passFilter( disp ) ) 00425 { 00426 // Send to the attached displayers 00427 for ( CDisplayers::iterator idi=_Displayers.begin(); idi!=_Displayers.end(); idi++ ) 00428 { 00429 (*idi)->display( *args, disp ); 00430 } 00431 } 00432 TempString = ""; 00433 unsetPosition(); 00434 } |
|
Display a string in decorated form to all attached displayers.
Definition at line 242 of file log.cpp. References _BypassFilterDisplayers, _Displayers, _LogType, _ProcessName, NLMISC::CLog::TDisplayInfo::CallstackAndLog, NLMISC::CLog::TDisplayInfo::Date, NLMISC::CLog::TDisplayInfo::Filename, NLMISC::getCallStackAndLog(), NLMISC::getThreadId(), NLMISC::CLog::TDisplayInfo::Line, LOG_ASSERT, LOG_ERROR, NLMISC::CLog::TDisplayInfo::LogType, passFilter(), NLMISC::CLog::TDisplayInfo::ProcessName, setDefaultProcessName(), TempArgs, TempString, NLMISC::CLog::TDisplayInfo::ThreadId, and unsetPosition().
00243 { 00244 const char *disp = NULL; 00245 TDisplayInfo localargs, *args = NULL; 00246 00247 setDefaultProcessName (); 00248 00249 if(strchr(str,'\n') == NULL) 00250 { 00251 if (TempString.empty()) 00252 { 00253 time (&TempArgs.Date); 00254 TempArgs.LogType = _LogType; 00255 TempArgs.ProcessName = *_ProcessName; 00256 TempArgs.ThreadId = getThreadId(); 00257 TempArgs.Filename = _FileName; 00258 TempArgs.Line = _Line; 00259 TempArgs.CallstackAndLog = ""; 00260 00261 TempString = str; 00262 } 00263 else 00264 { 00265 TempString += str; 00266 } 00267 return; 00268 } 00269 else 00270 { 00271 if (TempString.empty()) 00272 { 00273 time (&localargs.Date); 00274 localargs.LogType = _LogType; 00275 localargs.ProcessName = *_ProcessName; 00276 localargs.ThreadId = getThreadId(); 00277 localargs.Filename = _FileName; 00278 localargs.Line = _Line; 00279 localargs.CallstackAndLog = ""; 00280 00281 disp = str; 00282 args = &localargs; 00283 } 00284 else 00285 { 00286 TempString += str; 00287 disp = TempString.c_str(); 00288 args = &TempArgs; 00289 } 00290 } 00291 00292 // send to all bypass filter displayers 00293 for (CDisplayers::iterator idi=_BypassFilterDisplayers.begin(); idi!=_BypassFilterDisplayers.end(); idi++ ) 00294 { 00295 (*idi)->display( *args, disp ); 00296 } 00297 00298 // get the log at the last minute to be sure to have everything 00299 if(args->LogType == LOG_ERROR || args->LogType == LOG_ASSERT) 00300 { 00301 getCallStackAndLog (args->CallstackAndLog, 4); 00302 } 00303 00304 if (passFilter (disp)) 00305 { 00306 // Send to the attached displayers 00307 for (CDisplayers::iterator idi=_Displayers.begin(); idi!=_Displayers.end(); idi++ ) 00308 { 00309 (*idi)->display( *args, disp ); 00310 } 00311 } 00312 TempString = ""; 00313 unsetPosition(); 00314 } |
|
Display a raw text to the normal displayer but without filtering It's used by the Memdisplayer (little hack to work) Definition at line 485 of file log.cpp. References format, and NLMISC_CONVERT_VARGS. Referenced by NLMISC::CMemDisplayer::write().
00487 { 00488 if ( noDisplayer() ) 00489 { 00490 return; 00491 } 00492 00493 char *str; 00494 NLMISC_CONVERT_VARGS (str, format, 256/*NLMISC::MaxCStringSize*/); 00495 00496 TDisplayInfo args; 00497 CDisplayers::iterator idi; 00498 00499 // send to all bypass filter displayers 00500 for (idi=_BypassFilterDisplayers.begin(); idi!=_BypassFilterDisplayers.end(); idi++ ) 00501 { 00502 (*idi)->display( args, str ); 00503 } 00504 00505 // Send to the attached displayers 00506 for ( idi=_Displayers.begin(); idi!=_Displayers.end(); idi++ ) 00507 { 00508 (*idi)->display( args, str ); 00509 } 00510 } |
|
Return the first displayer selected by his name.
Definition at line 206 of file log.cpp. References _BypassFilterDisplayers, _Displayers, and nlwarning.
00207 { 00208 if (displayerName == NULL || displayerName[0] == '\0') 00209 { 00210 nlwarning ("LOG: Trying to get an empty displayer name"); 00211 return NULL; 00212 } 00213 00214 CDisplayers::iterator idi; 00215 for (idi = _Displayers.begin (); idi != _Displayers.end (); idi++) 00216 { 00217 if ((*idi)->DisplayerName == displayerName) 00218 { 00219 return *idi; 00220 } 00221 } 00222 for (idi = _BypassFilterDisplayers.begin (); idi != _BypassFilterDisplayers.end (); idi++) 00223 { 00224 if ((*idi)->DisplayerName == displayerName) 00225 { 00226 return *idi; 00227 } 00228 } 00229 return NULL; 00230 } |
|
Returns true if no displayer is attached.
Definition at line 95 of file log.h. References _BypassFilterDisplayers, and _Displayers. Referenced by setPosition(), and unsetPosition().
00095 { return _Displayers.empty() && _BypassFilterDisplayers.empty(); } |
|
Returns true if the string must be logged, according to the current filter.
Definition at line 517 of file log.cpp. References _NegativeFilter, and _PositiveFilter. Referenced by displayRawString(), and displayString().
00518 { 00519 bool yes = _PositiveFilter.empty(); 00520 00521 bool found; 00522 list<string>::iterator ilf; 00523 00524 // 1. Positive filter 00525 for ( ilf=_PositiveFilter.begin(); ilf!=_PositiveFilter.end(); ++ilf ) 00526 { 00527 found = ( strstr( filter, (*ilf).c_str() ) != NULL ); 00528 if ( found ) 00529 { 00530 yes = true; // positive filter passed (no need to check another one) 00531 break; 00532 } 00533 // else try the next one 00534 } 00535 if ( ! yes ) 00536 { 00537 return false; // positive filter not passed 00538 } 00539 00540 // 2. Negative filter 00541 for ( ilf=_NegativeFilter.begin(); ilf!=_NegativeFilter.end(); ++ilf ) 00542 { 00543 found = ( strstr( filter, (*ilf).c_str() ) != NULL ); 00544 if ( found ) 00545 { 00546 return false; // negative filter not passed (no need to check another one) 00547 } 00548 } 00549 return true; // negative filter passed 00550 } |
|
Remove a displayer using his name.
Definition at line 172 of file log.cpp. References _BypassFilterDisplayers, _Displayers, and nlwarning.
00173 { 00174 if (displayerName == NULL || displayerName[0] == '\0') 00175 { 00176 nlwarning ("LOG: Trying to remove an empty displayer name"); 00177 return; 00178 } 00179 00180 CDisplayers::iterator idi; 00181 for (idi = _Displayers.begin (); idi != _Displayers.end ();) 00182 { 00183 if ((*idi)->DisplayerName == displayerName) 00184 { 00185 idi = _Displayers.erase (idi); 00186 } 00187 else 00188 { 00189 idi++; 00190 } 00191 } 00192 00193 for (idi = _BypassFilterDisplayers.begin (); idi != _BypassFilterDisplayers.end ();) 00194 { 00195 if ((*idi)->DisplayerName == displayerName) 00196 { 00197 idi = _BypassFilterDisplayers.erase (idi); 00198 } 00199 else 00200 { 00201 idi++; 00202 } 00203 } 00204 } |
|
Remove a displayer. If the displayer doesn't work in a specific time, you could remove it.
Definition at line 150 of file log.cpp. References _BypassFilterDisplayers, _Displayers, and nlwarning. Referenced by NLNET::IService::main().
00151 { 00152 if (displayer == NULL) 00153 { 00154 nlwarning ("LOG: Trying to remove a NULL displayer"); 00155 return; 00156 } 00157 00158 CDisplayers::iterator idi = std::find (_Displayers.begin (), _Displayers.end (), displayer); 00159 if (idi != _Displayers.end ()) 00160 { 00161 _Displayers.erase (idi); 00162 } 00163 00164 idi = std::find (_BypassFilterDisplayers.begin (), _BypassFilterDisplayers.end (), displayer); 00165 if (idi != _BypassFilterDisplayers.end ()) 00166 { 00167 _BypassFilterDisplayers.erase (idi); 00168 } 00169 00170 } |
|
Removes a filter by name (in both filters).
Definition at line 556 of file log.cpp. References _NegativeFilter, and _PositiveFilter. Referenced by NLNET::cbLogFilter(), and NLMISC::NLMISC_COMMAND().
00557 { 00558 if (filterstr == NULL) 00559 { 00560 _PositiveFilter.clear(); 00561 _NegativeFilter.clear(); 00562 //displayNL ("CLog::addNegativeFilter('%s')", filterstr); 00563 } 00564 else 00565 { 00566 _PositiveFilter.remove( filterstr ); 00567 _NegativeFilter.remove( filterstr ); 00568 //displayNL ("CLog::removeFilter('%s')", filterstr); 00569 } 00570 } |
|
Reset both filters.
Definition at line 599 of file log.cpp. References _NegativeFilter, and _PositiveFilter. Referenced by NLMISC::NLMISC_COMMAND().
00600 { 00601 //displayNL ("CLog::resetFilter()"); 00602 _PositiveFilter.clear(); 00603 _NegativeFilter.clear(); 00604 } |
|
Find the process name if nobody call setProcessName before.
Definition at line 55 of file log.cpp. References _ProcessName. Referenced by displayRawString(), and displayString().
00056 { 00057 if (_ProcessName == NULL) 00058 { 00059 #undef new 00060 _ProcessName = new string; 00061 #define new NL_NEW 00062 } 00063 00064 #ifdef NL_OS_WINDOWS 00065 if ((*_ProcessName).empty()) 00066 { 00067 char name[1024]; 00068 GetModuleFileName (NULL, name, 1023); 00069 (*_ProcessName) = CFile::getFilename(name); 00070 } 00071 #else 00072 if ((*_ProcessName).empty()) 00073 { 00074 *_ProcessName = "<Unknown>"; 00075 } 00076 #endif 00077 } |
|
If !noDisplayer(), sets line and file parameters, and enters the mutex. If !noDisplayer(), don't forget to call display...() after, to release the mutex.
Definition at line 89 of file log.cpp. References _PosSet, noDisplayer(), and sint.
|
|
Set the name of the process.
Definition at line 79 of file log.cpp. References _ProcessName. Referenced by NLNET::IService::main().
00080 { 00081 if (_ProcessName == NULL) 00082 { 00083 _ProcessName = new string; 00084 } 00085 00086 *_ProcessName = processName; 00087 } |
|
Symetric to setPosition(). Automatically called by display...(). Do not call if noDisplayer().
Definition at line 101 of file log.cpp. References _PosSet, nlassert, and noDisplayer(). Referenced by displayRawString(), and displayString().
|
|
Definition at line 213 of file log.h. Referenced by addDisplayer(), attached(), displayRawString(), displayString(), getDisplayer(), noDisplayer(), and removeDisplayer(). |
|
Definition at line 211 of file log.h. Referenced by addDisplayer(), attached(), displayRawString(), displayString(), getDisplayer(), noDisplayer(), and removeDisplayer(). |
|
|
|
|
|
Definition at line 203 of file log.h. Referenced by displayString(). |
|
|
|
"Discard" filter
Definition at line 220 of file log.h. Referenced by addNegativeFilter(), displayFilter(), passFilter(), removeFilter(), and resetFilters(). |
|
"Crop" filter
Definition at line 223 of file log.h. Referenced by addPositiveFilter(), displayFilter(), passFilter(), removeFilter(), and resetFilters(). |
|
Definition at line 217 of file log.h. Referenced by setPosition(), and unsetPosition(). |
|
Definition at line 49 of file log.cpp. Referenced by displayString(), setDefaultProcessName(), and setProcessName(). |
|
Definition at line 232 of file log.h. Referenced by displayRawString(), and displayString(). |
|
Definition at line 231 of file log.h. Referenced by displayRawString(), and displayString(). |