• ### Popular Now

• 11
• 14
• 12
• 10
• 11

#### Archived

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

# best way to log error / successes ?

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

## Recommended Posts

##### Share on other sites
stdout and stderr are system defined as the console. If you want to send something to a file you will need to open a file and then pass the filehandle to fprintf.

FILE *log;

fopen(log,"log.txt","wt");
fprintf(log,"My error\n");
fclose(log);

##### Share on other sites
so should i jsut use fstreams then? because i know how to use fstreams, plus isnt it " a c++ thing" ??

or does the FILE stuff have an advantage? is it better for this situration? should i just learn it or stick to what i know? fstreams have been kind to me so far

##### Share on other sites
I am working on a tutorial based on a better tutorial.
You might want to take a look at the logfile stuff.

Read the disclaimer ... however the logfile part is pretty much the same as in a GOOD tutorial.

Breaktris Tutorial

##### Share on other sites
thanks for the link, but id prefer to not follow any tutorials. i like to learn things as i code . so can anyone confirm if i should just use fstreams to log everything?

Donkey Punch Productions.net

##### Share on other sites
you want to learn while coding? then why do you don''t make the choise by yourself and find out and learn while coding if its a good choise, or not?

If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

##### Share on other sites
yeah well, the thing is, if i were to code "blindly" and write a whole Logging class, and then it turns out this is compeltely wrong, well that would suck. programming is way to complicated and complex for me to take COMPLETE shots in the dark. i mean, the least i could do is ask for a simple "yes, that should be fine.", or "no, dont do that." i mean, its not like im asking for help with logic. taking shots in the dark with logic is fine, but with syntax? thats just dumb, you dont really get much out of learning what to NOT do with syntax (what do you gain? memorization? i can gain that from this post...)... of course, learning what to NOT do with logic is completely different. making mistakes with logic will teach you the ins and outs of how a program should flow (at least it has with me).

Donkey Punch Productions.net

##### Share on other sites
For my projects, I have a vector of strings. On program destruction, I write the strings to a log file. I also have an option to write "on the fly" in case I need to log events but get an access violation or a system hang or the like (something that stops normal program destruction).

Stay Clausal,

Red Sodium

##### Share on other sites
I use a singleton Log class that I use to log everything. I call it like this: Log::Get().Write(DEBUG, "debug message"). It allso has members like: AllLogsToStdOut(), ErrorsToStdOut(), and so on...

##### Share on other sites
fstreams are a good choice when logging errors, so if you don''t have code already using FILE pointers, go with C++ fstreams.

The big problem with writing a log to file is speed. If you write to the log every time you load an image, your game will load noticable slower. There are three popluar ways to get around this problem

1) create a string object, and write info into that. When the string reaches a certain size, write the string to a file, clear the string in memory, and start the process over. The only problem is there will be a noticable hickup in the game every time you write your string to file.

2) Only write errors to file. This method is the most stright foreward, but sometimes you need more information that just what went wrong.

3) Use C++ precompiler directives to designate certain parts of your code as DEBUG.

Ex.

// Put this line somewhere in main.h (or any other header that is linked with the whole project)#define _DEBUG_             // comment this line before release------------------------------------------------// everywhere you want to write to the log#ifdef _DEBUG_log << Message;#endif