EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyTraceLog Class Reference

a python client stack trace logger for Evemu More...

#include "PyTraceLog.h"

Public Member Functions

 PyTraceLog (const char *path, bool toConsole=false, bool toFile=false)
 The constructor of the python stack trace logger. More...
 
 ~PyTraceLog ()
 the destructor.... nothing special More...
 
bool logTrace (PyTuple &tuple)
 logTrace is the function what its all about. More...
 

Protected Member Functions

void _logInternStringMessage (PyRep *packet)
 
void _logInternBufferMessage (PyRep *packet)
 
void _logInternBufferPacket (PyRep *packet)
 
void _logInternMessage (const char *str,...)
 intern function for handling logger related messages More...
 
void _setLogColor (uint32 color)
 Internal function to set the console output color. More...
 

Private Attributes

FILE * mFout
 
bool mInitialized
 
bool mLogToConsole
 
bool mLogToFile
 

Detailed Description

a python client stack trace logger for Evemu

The PyTraceLog class processes the alert messages into a readable message, because its part of the development system it should be used by non developers.

Author
Captnoord
Date
December 2008

Definition at line 74 of file PyTraceLog.h.

Constructor & Destructor Documentation

PyTraceLog::PyTraceLog ( const char *  path,
bool  toConsole = false,
bool  toFile = false 
)
inline

The constructor of the python stack trace logger.

The constructor of the python stack trace logger.

Parameters
[in]pathThe path to the file including the file extension (basic for now).
[in]toConsoleWhen want to have the output written to the console pass true.
[in]toFileWhen want to have the output written to the specified file pass true.

Definition at line 85 of file PyTraceLog.h.

References mFout, mInitialized, and mLogToConsole.

86  : mFout(NULL),
87  mInitialized(false),
88  mLogToConsole(toConsole),
89  mLogToFile(toFile)
90 #ifdef HAVE_WINDOWS_H
91  ,mStderrHandle(NULL),
92  mStdoutHandle(NULL)
93 #endif /* HAVE_WINDOWS_H */
94  {
95  if (toFile == true)
96  {
97  mFout = fopen(path, "w+");
98  if (mFout == NULL)
99  printf("[error]PyTraceLog: sorry initializing the output file failed\n");
100  }
101 
102 #ifdef HAVE_WINDOWS_H
103  // get error handle
104  if (mLogToConsole == true)
105  {
106  mStderrHandle = GetStdHandle(STD_ERROR_HANDLE);
107  mStdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
108  }
109 #endif /* HAVE_WINDOWS_H */
110  mInitialized = true;
111  }
bool mLogToFile
Definition: PyTraceLog.h:316
FILE * mFout
Definition: PyTraceLog.h:313
bool mLogToConsole
Definition: PyTraceLog.h:315
bool mInitialized
Definition: PyTraceLog.h:314
PyTraceLog::~PyTraceLog ( )
inline

the destructor.... nothing special

Definition at line 116 of file PyTraceLog.h.

References mFout, and mLogToFile.

117  {
118  if (mLogToFile == true && mFout != NULL)
119  {
120  fflush(mFout);
121  fclose(mFout);
122  }
123  }
bool mLogToFile
Definition: PyTraceLog.h:316
FILE * mFout
Definition: PyTraceLog.h:313

Member Function Documentation

void PyTraceLog::_logInternBufferMessage ( PyRep packet)
inlineprotected

Definition at line 213 of file PyTraceLog.h.

References PyRep::AsBuffer(), PyBuffer::content(), mFout, mLogToConsole, mLogToFile, and PyBuffer::size().

214  {
215  PyBuffer & msg = *packet->AsBuffer();
216  if (mLogToConsole == true)
217  {
218  fwrite(&msg.content()[0], msg.size(), 1, stdout);
219  fputc('\n', stdout);
220  }
221 
222  if (mLogToFile == true)
223  {
224  fwrite(&msg.content()[0], msg.size(), 1, mFout);
225  fputc('\n', mFout);
226  }
227  }
const Buffer & content() const
Get the const PyBuffer content.
Definition: PyRep.h:407
bool mLogToFile
Definition: PyTraceLog.h:316
size_t size() const
Obtains length of the buffer.
Definition: PyRep.cpp:422
FILE * mFout
Definition: PyTraceLog.h:313
PyBuffer * AsBuffer()
Definition: PyRep.h:130
Python buffer.
Definition: PyRep.h:382
bool mLogToConsole
Definition: PyTraceLog.h:315

Here is the call graph for this function:

void PyTraceLog::_logInternBufferPacket ( PyRep packet)
inlineprotected

Definition at line 230 of file PyTraceLog.h.

References PyRep::AsString(), PyString::content(), PyRep::GetType(), mFout, mLogToConsole, mLogToFile, and PyRep::PyTypeString.

Referenced by logTrace().

231  {
232  // just placement code atm...
233  /*PyBuffer & msg = *packet->AsBuffer();
234  if (mLogToConsole == true)
235  {
236  fwrite(&msg.content()[0], msg.size(), 1, stdout);
237  fputc('\n', stdout);
238  }
239 
240  if (mLogToFile == true)
241  {
242  fwrite(&msg.content()[0], msg.size(), 1, mFout);
243  fputc('\n', mFout);
244  }*/
245 
246  if (packet->GetType() != PyRep::PyTypeString)
247  return;
248 
249  PyString & msg = *packet->AsString();
250  if (mLogToConsole == true)
251  {
252  fwrite(msg.content().c_str(), msg.content().size(), 1, stdout);
253  fputc('\n', stdout);
254  }
255 
256  if (mLogToFile == true)
257  {
258  fwrite(msg.content().c_str(), msg.content().size(), 1, mFout);
259  fputc('\n', mFout);
260  }
261 
262  }
Python string.
Definition: PyRep.h:430
bool mLogToFile
Definition: PyTraceLog.h:316
PyType GetType() const
Definition: PyRep.h:98
FILE * mFout
Definition: PyTraceLog.h:313
PyString * AsString()
Definition: PyRep.h:132
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
bool mLogToConsole
Definition: PyTraceLog.h:315

Here is the call graph for this function:

Here is the caller graph for this function:

void PyTraceLog::_logInternMessage ( const char *  str,
  ... 
)
inlineprotected

intern function for handling logger related messages

intern function for handling logger related messages

Parameters
[in]strthe format for the output message.

Definition at line 271 of file PyTraceLog.h.

References _setLogColor(), mFout, mLogToConsole, mLogToFile, TNORMAL, and TRED.

Referenced by logTrace().

272  {
273  va_list ap;
274  va_start(ap, str);
275 
277  // I know its code duplication....on a small scale
278  if (mLogToConsole == true)
279  {
280  fprintf(stdout, "[PyTrace] ");
281  vfprintf(stdout, str, ap);
282  putc('\n', stdout);
283  }
284 
285  if (mLogToFile == true)
286  {
287  fprintf(mFout, "[PyTrace] ");
288  vfprintf(mFout, str, ap);
289  putc('\n', mFout);
290  fflush(mFout);
291  }
293  va_end(ap);
294  }
bool mLogToFile
Definition: PyTraceLog.h:316
#define TRED
Definition: PyTraceLog.h:40
FILE * mFout
Definition: PyTraceLog.h:313
bool mLogToConsole
Definition: PyTraceLog.h:315
void _setLogColor(uint32 color)
Internal function to set the console output color.
Definition: PyTraceLog.h:303
#define TNORMAL
Definition: PyTraceLog.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

void PyTraceLog::_logInternStringMessage ( PyRep packet)
inlineprotected

Definition at line 199 of file PyTraceLog.h.

References PyRep::AsString(), PyString::content(), mFout, mLogToConsole, and mLogToFile.

200  {
201  PyString & msg = *packet->AsString();
202  if (mLogToConsole == true)
203  {
204  fprintf(stdout, "%s\n", msg.content().c_str());
205  }
206 
207  if (mLogToFile == true)
208  {
209  fprintf(mFout, "%s\n", msg.content().c_str());
210  }
211  }
Python string.
Definition: PyRep.h:430
bool mLogToFile
Definition: PyTraceLog.h:316
FILE * mFout
Definition: PyTraceLog.h:313
PyString * AsString()
Definition: PyRep.h:132
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
bool mLogToConsole
Definition: PyTraceLog.h:315

Here is the call graph for this function:

void PyTraceLog::_setLogColor ( uint32  color)
inlineprotected

Internal function to set the console output color.

Lazy ass function for a developer "toy". We humans like to see some colors.

Parameters
[in]colorthe color flags / value's for Windows or UNIX, see TRED and the rest on top of this file.

Definition at line 303 of file PyTraceLog.h.

References colorstrings, and TNORMAL.

Referenced by _logInternMessage().

304  {
305 #ifdef HAVE_WINDOWS_H
306  SetConsoleTextAttribute(mStdoutHandle, TNORMAL);
307 #else /* !HAVE_WINDOWS_H */
308  puts(colorstrings[TNORMAL]);
309 #endif /* !HAVE_WINDOWS_H */
310  }
static const char * colorstrings[TBLUE+1]
Definition: PyTraceLog.h:50
#define TNORMAL
Definition: PyTraceLog.h:43

Here is the caller graph for this function:

bool PyTraceLog::logTrace ( PyTuple tuple)
inline

logTrace is the function what its all about.

the logTrace function processes the packet object into the readable text and prints it to the screen and or the output file.

Parameters
[in]tupletuple contains the packet info of the trace.
Returns
returns true if a success and false if a error is found (no special error handling for now).

Definition at line 133 of file PyTraceLog.h.

References _logInternBufferPacket(), _logInternMessage(), PyTuple::GetItem(), PyRep::IsTuple(), mFout, mInitialized, and mLogToFile.

Referenced by AlertService::Handle_SendClientStackTraceAlert().

134  {
135  assert(mInitialized && "PyTraceLog isn't initialized");
136 
137  // base object should be a tuple
138  if(tuple.IsTuple() == false)
139  {
140  _logInternMessage("trace error because the base object isn't a tuple");
141  return false;
142  }
143 
144  /* the next part is commented out because the payload of the error message contains similar data */
145 
146  // the first object should be a tuple
147  /*if (tuple[0]->IsTuple() == false)
148  {
149  _logInternMessage("trace error because the first object within the tuple isn't a tuple");
150  return false;
151  }
152 
153  if (mLogToFile)
154  fprintf(mFout, "\nStackTraceAlert:\n");
155 
156  // tuple 0 should contain the error message or something binary
157  PyRepTuple& tuple0_0 = tuple[0]->AsTuple();
158  //tuple0_0[0] some integer... which I don't care about
159  if( tuple0_0[1]->IsString() == true )
160  {
161  _logInternStringMessage(tuple0_0[1]);
162  }
163  else if (tuple0_0[1]->IsBuffer() == true)
164  {
165  _logInternBufferMessage(tuple0_0[1]);
166  }
167  else
168  {
169  _logInternMessage("trace log error");
170  return false;
171  }
172 
173  if (mLogToFile == true)
174  {
175  fputc('\n', mFout);
176  fflush(mFout);
177  }*/
178 
179  /* python stack trace payload */
180  //if (tuple.GetItem(1)->IsString() == true)
181  {
183  }
184 
185  if (mLogToFile == true)
186  {
187  fputc('\n', mFout);
188  fflush(mFout);
189  }
190 
191  //tuple[2] should contain a string "Error" but that is a assumption and I am sure it has more stings to give us.
192  //tuple[3] gives me for the moment the object None. So its marked as unknown for the moment.
193 
194  return true;
195  }
void _logInternMessage(const char *str,...)
intern function for handling logger related messages
Definition: PyTraceLog.h:271
void _logInternBufferPacket(PyRep *packet)
Definition: PyTraceLog.h:230
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
bool IsTuple() const
Definition: PyRep.h:108
bool mLogToFile
Definition: PyTraceLog.h:316
FILE * mFout
Definition: PyTraceLog.h:313
bool mInitialized
Definition: PyTraceLog.h:314

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool PyTraceLog::mInitialized
private

Definition at line 314 of file PyTraceLog.h.

Referenced by logTrace(), and PyTraceLog().

bool PyTraceLog::mLogToConsole
private
bool PyTraceLog::mLogToFile
private

The documentation for this class was generated from the following file: