Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

moronmaster

Debug logger or data logger strategy

This topic is 5570 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i was trying to develop a good way to provide my program a simple yet flexible data logger (basically records debbug messages to a text file). Flexible meaning i can set what kinds of debug messages i want recorded at run time rather than having to keep going back to the code to comment out or add in debug messages. So what i do is something like this: //I create an array of BOOL''s BOOL debug_flag[100]; //intialize them all to FALSE //then for printing my debug messages i create a simple function debug_log ("my message", 10); //the debug_log function would be something like: BOOL debug_log (char* log_message, int debug_id) { if (debug_flag[debug_id] == TRUE) { fprintf (logfile, "%s",log_message); fflush (logfile); //print to file immediately return (TRUE); //successful } return (FALSE); //no debug message recorded } ------------------------------------------------------- So now if i set debug_flag[10] = TRUE i will only get all those debug messages i called with the value 10. This means however the debug_flag[] is global in order to use it throughout my code. How do you all do your debug messages? Is the way i am doing it useful or is it just a waste of time? Is there better ways for doing this?

Share this post


Link to post
Share on other sites
Advertisement
I only use debug messages when there is a problem and afterwards when I've fixed the problem, I remove them. Sooner or later you will end up with so much code, that you'll be spending lots of time writing debug messages (waste of time).

you could easilly encapsulate the global debug_flag data by doing:

// -- header file --

void set_debug_log_level(int level);
void debug_log(const char *message, int level);

// -- c file --

static bool s_enabled[10]; // 100 seems a little big


set_debug_log_level(int level)
{
s_enabled[level] = true;
}

void debug_log(const char *message, int level)
{
if(s_enabled[level])
{
print_debug_message_somehow();
}
}


if you didn't want certain "levels" to be enabled/disabled I suggest you do:


// -- c file --

static int s_level;

set_debug_log_level(int level)
{
s_level = level;
}

void debug_log(const char *message, int level)
{
if(level <= s_level)
{
print_debug_message_somehow();
}
}


you could also do this the c++ way with a singleton or some static member functions with some static member data.

[edited by - doho on June 19, 2003 4:53:32 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!