Click to See Complete Forum and Search --> : need to know best bethod of Logging.


ramkumarthangam
January 6th, 2002, 02:02 AM
Hi, can you please suggest me the best method to log the data to a file. For example, in a protocol implementation, when the application is running, we need to log the messages that it receives/transmits. since,after long run the file size get increased so that the performance get affected.



"We are what we repeatedly do.
Excellence then is not an act,
but a habit" - Aristotle

NMTop40
January 7th, 2002, 04:26 AM
My own preference is to use a singleton class. I also prefer to set a logging level in the class.

Then my own preference is to use a sprintf() style of output, and the class itself calls vsprintf() to log. After each write I always flush the buffer. You can also optionally time-stamp but that depends on the nature of the program.

The log level and the timestamp option are class (can be static) members.

However I then use macros to call the class functions, as you can then switch logging off altogether (for release versions etc) simply by modifying the macro, and you don't even need to edit the code to do that - you can simply use a preprocessor define in the _DEBUG but not in the release version.


The best things come to those who rate