Jump to content
  • Advertisement

Archived

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

MindWipe

Logging, how do I do that?

This topic is 6376 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

I just need a funktion that saves some text like "DirectDraw init - OK" and/or "Shutdown complete" But the only save to file method I know saves it like many weird ACHII. Can anyone post his/her log funktion? I need a easy to use funktion like AddToLog("bla bla"); I thankful for any help /MindWipe "If it doesn''t fit, force it; if it breaks, it needed replacement anyway."

Share this post


Link to post
Share on other sites
Advertisement
the easiest way would be file streams
you create the objekt
check if its ok
and store data by using just the << operator

example:
ofstream save(strFileName);

if (save.good())
{
save << somthing << something_else;
}
save.close();

you can save any basic type from int to char

der_meista

Share this post


Link to post
Share on other sites
Have you tried following:

At init:
FILE* log=fopen("mylog.txt","wt");

when at any place
fprintf(log,"DirectDraw init OK\n");

and at end:
fclose(log);

This is more convenient than streams cause you may use expression like:
fprint(log,"%s %d %f",string,intval,floatval);
to print values to log (I found it very useful, and not only I)

Or you programming in Delphi of Visual Basic?
Hope you find it useful

Edited by - nullguid on January 29, 2001 2:48:36 PM

Share this post


Link to post
Share on other sites
something like this?

    
bool State_Protokollfileopened = false;
void Log(char* st, ...)
{
if(st == NULL)
return;

FILE* protokollfile = fopen("protokoll.log", "a+t");
if(State_Protokollfileopened)
{
fseek(protokollfile, 0, SEEK_SET);
State_Protokollfileopened = true;
}
else
fseek(protokollfile, 0, SEEK_END);

char output[800];
va_list ap;
va_start(ap, st); // Parses The String For Variables

vsprintf(output, st, ap); // And Converts Symbols To

va_end(ap);

fprintf(protokollfile, "%s\n", output);

fclose(protokollfile);
}



I just took this from my leveleditor. had to take some things out, so if somethings wrong, just e-mail me....
cya,
Phil

Uh, btw.. you can use this function just as any format function (just like sscanf, fprintf, printf, an so on)...

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Edited by - phueppl1 on January 29, 2001 2:48:17 PM

Share this post


Link to post
Share on other sites
nullguid> Yup I''m using C++, I think I''ll use your method. Looks easiest. Thankx.

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."

Share this post


Link to post
Share on other sites
MindWipe, if you use C++ you might want to consider creating a LogFile class and make it a little more robust (support for multiple log files, debug levels for logging, displaying message to output window and/or printer, etc).

BTW, if you are going to log successful function calls (ie, DirectDraw init - OK) I''d recommend against opening/closing your file after every single log. It''ll kill your performance.


- Houdini

Share this post


Link to post
Share on other sites
BTW im revamping a general logfile and im a little stumped for ideas. Do anyone have suggestions or wishlists for things to be included in a logfile ?

WHO DO THEY
THINK THEY''RE
FOOLING : YOU ?



GARAL website

Share this post


Link to post
Share on other sites
I would love to see multiple log files supported as well as auto indenting. So if you are like loading a level, you could indent it and show all the portions of the level that loaded... that would be nice

Timestamping would be a nice and easy feature as well.

Spanky

Share this post


Link to post
Share on other sites
You can also keep a log in RAM, which you''d want to do if you had a drop-down console for users to read as it is updated. You''d also need something like this for a message queue for RPGs or strategy games (conversations for RPGs, commands issued for strategy games). It would be this:


  
struct MessageLog
{
char* Message;
MessageLog* NextEntry;
};
//

MessageLog g_Log; // I''ll use a global for this example

//

void InitLog ( )
{
g_Log.Message = NULL;
g_Log.NextEntry = NULL;
}
//

void AddEntry ( char* NewMessage )
{
MessageLog* Temp;

if( !g_Log.Message ) g_Log.Message = NewMessage;
else
{
Temp = &g_Log;
//

while( Temp->NextEntry )
Temp = Temp->NextEntry;

Temp->NextEntry = new MessageLog;
Temp->NextEntry->Message = NewMessage;
Temp->NextEntry->NextEntry = NULL;
}
}
//

void DeleteLog ( )
{
MessageLog* Temp;
MessageLog* Next;
//

if( g_Log.Message ) delete [] g_Log.Message;
g_Log.Message = NULL;
Temp = g_Log.NextEntry;
g_Log.NextEntry = NULL;
//

while( Temp )
{
if( Temp->Message ) delete [] Temp->Message;
Next = Temp->NextEntry;
delete Temp;
Temp = Next;
}
}


~CGameProgrammer( );

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!