#include <displayer.h>
Inheritance diagram for NLMISC::CStdDisplayer:

Nevrax France
Definition at line 102 of file displayer.h.
Public Member Functions | |
| CStdDisplayer (const char *displayerName="") | |
| void | display (const CLog::TDisplayInfo &args, const char *message) |
| Display the string where it does. | |
Static Public Member Functions | |
| const char * | dateToComputerString (time_t date) |
| Convert date to "784551148" string (time in second from 1975). | |
| const char * | dateToHumanString (time_t date) |
| Convert date to "2000/01/14 10:05:17" string. | |
| const char * | dateToHumanString () |
| Convert the current date to human string. | |
| const char * | logTypeToString (CLog::TLogType logType, bool longFormat=false) |
| Convert log type to string. | |
Data Fields | |
| std::string | DisplayerName |
| This is the idenfiant for a displayer, it is used to fond or remove a displayer. | |
Protected Member Functions | |
| virtual void | doDisplay (const CLog::TDisplayInfo &args, const char *message) |
| Display the string to stdout and OutputDebugString on Windows. | |
Static Protected Member Functions | |
| const char * | HeaderString () |
|
|
Definition at line 105 of file displayer.h.
00105 : IDisplayer (displayerName) {} |
|
|
Convert date to "784551148" string (time in second from 1975).
Definition at line 103 of file displayer.cpp. References NLMISC::smprintf().
00104 {
00105 static char cstime[25];
00106 smprintf (cstime, 25, "%ld", &date);
00107 return cstime;
00108 }
|
|
|
Convert date to "2000/01/14 10:05:17" string.
Definition at line 92 of file displayer.cpp. References uint32.
00093 {
00094 static char cstime[25];
00095 struct tm *tms = localtime(&date);
00096 if (tms)
00097 strftime (cstime, 25, "%Y/%m/%d %H:%M:%S", tms);
00098 else
00099 sprintf(cstime, "bad date %d", (uint32)date);
00100 return cstime;
00101 }
|
|
|
Convert the current date to human string.
Definition at line 85 of file displayer.cpp. Referenced by NLNET::CNetDisplayer::doDisplay(), NLMISC::CMemDisplayer::doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and NLMISC::IDisplayer::HeaderString().
00086 {
00087 time_t date;
00088 time (&date);
00089 return dateToHumanString (date);
00090 }
|
|
||||||||||||
|
Display the string where it does.
Definition at line 132 of file displayer.cpp. References NLMISC::IDisplayer::doDisplay().
|
|
||||||||||||
|
Display the string to stdout and OutputDebugString on Windows.
Implements NLMISC::IDisplayer. Definition at line 148 of file displayer.cpp. References NLMISC::CLog::TDisplayInfo::CallstackAndLog, count, NLMISC::CLog::TDisplayInfo::Filename, IsDebuggerPresent, NLMISC::CLog::TDisplayInfo::Line, NLMISC::CLog::TDisplayInfo::LogType, NLMISC::IDisplayer::logTypeToString(), NLMISC::CLog::TDisplayInfo::ProcessName, s, sint, NLMISC::CLog::TDisplayInfo::ThreadId, NLMISC::toString(), uint, and uint32.
00149 {
00150 bool needSpace = false;
00151 //stringstream ss;
00152 string str;
00153
00154 if (args.LogType != CLog::LOG_NO)
00155 {
00156 //ss << logTypeToString(args.LogType);
00157 str += logTypeToString(args.LogType);
00158 needSpace = true;
00159 }
00160
00161 // Write thread identifier
00162 if ( args.ThreadId != 0 )
00163 {
00164 //ss << setw(5) << args.ThreadId;
00165 str += NLMISC::toString("%5u", args.ThreadId);
00166 needSpace = true;
00167 }
00168
00169 if (args.Filename != NULL)
00170 {
00171 //if (needSpace) { ss << " "; needSpace = false; }
00172 if (needSpace) { str += " "; needSpace = false; }
00173 //ss << CFile::getFilename(args.Filename);
00174 str += CFile::getFilename(args.Filename);
00175 needSpace = true;
00176 }
00177
00178 if (args.Line != -1)
00179 {
00180 //if (needSpace) { ss << " "; needSpace = false; }
00181 if (needSpace) { str += " "; needSpace = false; }
00182 //ss << args.Line;
00183 str += NLMISC::toString(args.Line);
00184 needSpace = true;
00185 }
00186
00187 if (!args.ProcessName.empty())
00188 {
00189 //if (needSpace) { ss << " "; needSpace = false; }
00190 if (needSpace) { str += " "; needSpace = false; }
00191 //ss << args.ProcessName;
00192 str + args.ProcessName;
00193 needSpace = true;
00194 }
00195
00196 //if (needSpace) { ss << " : "; needSpace = false; }
00197 if (needSpace) { str += " : "; needSpace = false; }
00198
00199 //ss << message;
00200 str += message;
00201
00202 // string s = ss.str();
00203
00204 static bool consoleMode = true;
00205
00206 #if defined(NL_OS_WINDOWS)
00207 static bool consoleModeTest = false;
00208 if (!consoleModeTest)
00209 {
00210 HANDLE handle = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
00211 consoleMode = handle != INVALID_HANDLE_VALUE;
00212 if (consoleMode)
00213 CloseHandle (handle);
00214 consoleModeTest = true;
00215 }
00216 #endif // NL_OS_WINDOWS
00217
00218 // Printf ?
00219 if (consoleMode)
00220 {
00221 // we don't use cout because sometimes, it crashs because cout isn't already init, printf doesn t crash.
00222 if (!str.empty())
00223 printf ("%s", str.c_str());
00224
00225 if (!args.CallstackAndLog.empty())
00226 printf (args.CallstackAndLog.c_str());
00227
00228 fflush(stdout);
00229 }
00230
00231 #ifdef NL_OS_WINDOWS
00232 // display the string in the debugger is the application is started with the debugger
00233 if (IsDebuggerPresent ())
00234 {
00235 //stringstream ss2;
00236 string str2;
00237 needSpace = false;
00238
00239 if (args.Filename != NULL) str2 += args.Filename;
00240
00241 if (args.Line != -1)
00242 {
00243 str2 += "(" + NLMISC::toString(args.Line) + ")";
00244 needSpace = true;
00245 }
00246
00247 if (needSpace) { str2 += " : "; needSpace = false; }
00248
00249 if (args.LogType != CLog::LOG_NO)
00250 {
00251 str2 += logTypeToString(args.LogType);
00252 needSpace = true;
00253 }
00254
00255 // Write thread identifier
00256 if ( args.ThreadId != 0 )
00257 {
00258 str2 += NLMISC::toString("%5u: ", args.ThreadId);
00259 }
00260
00261 str2 += message;
00262
00263 const sint maxOutString = 2*1024;
00264
00265 if(str2.size() < maxOutString)
00266 {
00268 // WARNING: READ THIS !!!!!!!!!!!!!!!! ///////////////////////////
00269 // If at the release time, it freezes here, it's a microsoft bug:
00270 // http://support.microsoft.com/support/kb/articles/q173/2/60.asp
00271 OutputDebugString(str2.c_str());
00272 }
00273 else
00274 {
00275 /*OutputDebugString(ss2.str().c_str());
00276 OutputDebugString("\n\t\t\t");
00277 OutputDebugString("message end: ");
00278 OutputDebugString(&message[strlen(message) - 1024]);
00279 OutputDebugString("\n");*/
00280
00281 sint count = 0;
00282 uint n = strlen(message);
00283 std::string s(&str2.c_str()[0], (str2.size() - n));
00284 OutputDebugString(s.c_str());
00285
00286 while(true)
00287 {
00288
00289 if((n - count) < maxOutString )
00290 {
00291 s = std::string(&message[count], (n - count));
00292 OutputDebugString(s.c_str());
00293 OutputDebugString("\n");
00294 break;
00295 }
00296 else
00297 {
00298 s = std::string(&message[count] , count + maxOutString);
00299 OutputDebugString(s.c_str());
00300 OutputDebugString("\n\t\t\t");
00301 count += maxOutString;
00302 }
00303 }
00304 }
00305
00306 // OutputDebugString is a big shit, we can't display big string in one time, we need to split
00307 uint32 pos = 0;
00308 string splited;
00309 while(true)
00310 {
00311 if (pos+1000 < args.CallstackAndLog.size ())
00312 {
00313 splited = args.CallstackAndLog.substr (pos, 1000);
00314 OutputDebugString(splited.c_str());
00315 pos += 1000;
00316 }
00317 else
00318 {
00319 splited = args.CallstackAndLog.substr (pos);
00320 OutputDebugString(splited.c_str());
00321 break;
00322 }
00323 }
00324 }
00325 #endif
00326 }
|
|
|
Definition at line 110 of file displayer.cpp. References NLMISC::IDisplayer::dateToHumanString(), and NLMISC::smprintf(). Referenced by NLMISC::CMemDisplayer::doDisplay(), and NLMISC::CFileDisplayer::doDisplay().
00111 {
00112 static char header[1024];
00113 smprintf(header, 1024, "\nLog Starting [%s]\n", dateToHumanString());
00114 return header;
00115 }
|
|
||||||||||||
|
Convert log type to string.
Definition at line 77 of file displayer.cpp. References NLMISC::LogTypeToString. Referenced by NLMISC::CWindowDisplayer::doDisplay(), NLNET::CNetDisplayer::doDisplay(), NLMISC::CMemDisplayer::doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and doDisplay().
00078 {
00079 if (logType < CLog::LOG_NO || logType > CLog::LOG_UNKNOWN)
00080 return "<NotDefined>";
00081
00082 return LogTypeToString[longFormat?1:0][logType];
00083 }
|
|
|
This is the idenfiant for a displayer, it is used to fond or remove a displayer.
Definition at line 63 of file displayer.h. Referenced by NLMISC::IDisplayer::IDisplayer(). |
1.3.6