Archived

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

Sand_Hawk

Error logging

Recommended Posts

Hi guys, I''m on a team of newbie game programmers. We all are working on a little project of our own and when done we send our code to team members for code review or help. In this way we can learn from eachother and when we are all a bit better than now we want to create a 2D game as a team. Currently I''m working on a error log class. CLog holds 1 char* var wich represents the log file. I already implemented writing into the log file like this: open file, write to file, flush buffer, close file. You can also set the output file name. What else do I need to implement in the log class. I want thinking about date/time reporting but that would make it less portable. I had the idea of letting the programmer create the log string so the programmers can report whatever he likes(Date time, sourcefile, Error message). Do I need anything else in my class than setting the output file and a WriteLog(char* myMessage) function??? TIA, Sand Hawk Member of the Stupid Coders. http://www.stupidcoders.cjb.net -Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
ello,
Maybe this will help:

http://www.gamedev.net/community/forums/topic.asp?topic_id=70197

I just made a few logging functions and decided it would help to have the line numbers and filename included (__LINE__ and __FILE__) to help debug large projects.


hope this helps,
rich

Edited by - burnseh on December 10, 2001 8:32:49 AM

Share this post


Link to post
Share on other sites
Writing a log class usually ends up in being a rather huge task. Bacially what I put in mine is:

// Definition on the file name
LogFile(char* _fileName)
ErrorFile(char* _fileName)
WarningFile(char* _fileName)
InfoFile(char* _fileName)

// Either write a info, warning or error string
Info(char* _file, int _line, char* _text)
Warning(char* _file, int _line, char* _text)
Error(char* _file, int _line, char* _text)
DumpLog()

All output go to the logfile and then the different types of output go to the specific file if it''s set. I made it mandatory to fill in file and line, since otherwise these might be skipped, and also implementation on how these are collected is moved outside the log class. I''ve created a time class which outputs the time, which is used in log, so if I need to port it it might only be the time class which needs to be rewritten.

In order not to slow performance too much I''ve implemented a dump log method, and only when calling that or when deleting the object I write to the files.

Each string looks something like this:
[T123456789] [TIME] [FILE] -> [TEXT]

The first group are flags which can be set, the first tells me what type if info this is (info, warning or error), the rest is used for other stuff. The reason for such much info is that I''m going to do a tool that can be used to go through the log and generate some statistics.

Info and Warning are things that might give a system crash, but did''nt cause it, and stuff like that.

Well hope that gave you some ideas of what I do with logging.

-- Sturm

---------------------------------------------------
Life after death? No thanks, I want to live NOW
--- Sturm 2001

Share this post


Link to post
Share on other sites