I suppose ther are as many ways to write a logger as there are progammers. The way I did it was to write a funtion that took a const char* as parameter (the message to be logged), open the log file, write out the message, then close the file. Its a very simple function. Then you can call that function as many times in your program as you want to.
If you only want to do the logging when the program is compiled for degging then you might do something like this:
void log(const char* message)
// code to log messages go here