Skip to main content
GameDev.net gamedev.net
🔒 Locked

A logging File System for a game Engine

Started by 3dmodelerguy Feb 26, 2005 at 2:09 PM 9 replies 7k views
Original Post
3dmodelerguy
3dmodelerguy
Hey i am needed to create a logging systemthat logs what ever the engine does into a file. are there any existing logging systems that can do this or any tutorials on how to create them?
JimPrice
JimPrice
Enginuity, part II has a logger class in it - I've nicked it as written, and it's met all my needs perfectly.

Jim.
IFooBar
IFooBar
I wrote a few debugging utilities that can be found here. There's a logger there too, so you can check that out.
[size=2]aliak.net
chbrules
chbrules
Are you just looking for a logging function that appends data to a log file? You could just use something simple like this that I did in an old project a while ago. When you call it, just do Log("this will be logged");

void Log(char Log[]){	ofstream out;	out.open( _LOG_ , ios_base::app);	out << endl << Log;	out.close();}
-Conrad
3dmodelerguy
3dmodelerguy
are there any tutorials that would help me in outputting the file into HTML format
Agentidd
Agentidd
Its not very hard to make your own utility to do this. Just write a console program that opens that file and outputs it in the format that you want.

ie, catch the first line "GAME LOG 02/26/2005 8:00 AM", write to a file < h1>

GAME LOG 02/26/2005 8:00 AM

and continue from there. My program simply just made it more readable, I wasn't after naything too fancy. You can also format Codes into the logger. Such as that each line is preceeded by a 1 for headers, 2 for certain type of text... etc etc. Then save as a html and open in any browser.

I'm sure you see where this is going. If you are always going to view your log in html, you might go as far as to code it into the engine. The seperate utility has always worked good for me. I find it to be a quicker and easier to make changes since it has only 1 purpose. You can probably tackle this in an extremely short amount of time. If you need further help, google for some tutorials and brush up on importing, editing, and exporting text files.

-Brent
raydog
raydog
Use something simple like this. You can write out formatted text, like:

Log("Number: %d\n", some_variable );
or
Log("Hello.\n");

///////////////////////////////////////

#define MAX_MESSAGE 2048

void Log(const char* const out, ...) {

char message[MAX_MESSAGE];

va_list argptr;
va_start(argptr, out);
vsnprintf(message, MAX_MESSAGE, out, argptr);
va_end(argptr);

// your function to write to file or stdout
WriteLog(message);
}

JavaCoolDude
JavaCoolDude
#ifndef LOGGER_H#define LOGGER_H#include "../Glee/GLee.h"class Logger{  public:    static void writeFatalErrorLog(const char* format,...);    static bool writeErrorLog(const char* format,...);    static void writeLog(const char* format,...);};#endif#include "Logger.h"void Logger::writeLog(const char* format,...){  ofstream logFile("Log.txt", ios::app);  char     stringBuffer[256];  va_list  arguments;  va_start(arguments, format);  vsprintf(stringBuffer, format, arguments);  va_end(arguments);      logFile << stringBuffer;  logFile.close();}bool Logger::writeErrorLog(const char* format,...){  ofstream logFile("Log.txt", ios::app);  char     stringBuffer[256];  va_list  arguments;  va_start(arguments, format);  vsprintf(stringBuffer, format, arguments);  va_end(arguments);      logFile << stringBuffer;  logFile.close();  return false;}void Logger::writeFatalErrorLog(const char* format,...){  char stringBuffer[256];  ofstream logFile("Log.txt", ios::app);  va_list  arguments;  va_start(arguments, format);  vsprintf(stringBuffer, format, arguments);  va_end(arguments);      logFile << stringBuffer;  logFile << endl;  logFile.close();  exit(1);}
snk_kid
snk_kid
Quote:
Original post by JavaCoolDude
....


You guys and your variable argument lists [lol], wait and see what happens when you pass user-defined types to it such as std::basic_string watch your computer implode [wink].

If you really want printf style but gels in & with C++ user-defined types have a look into boost::format

[Edited by - snk_kid on February 27, 2005 12:04:59 PM]
Conner McCloud
Conner McCloud
Quote:
Original post by JavaCoolDude
*** Source Snippet Removed ***

Don't use vsprintf like that. Ever. You've got two options that, I believe, are part of the standard library. They're definately available through VC++, at the very least.

(1) vsnprintf

(2) _vscprintf

Even then, you are limited to simple data, and have no parameter checking. So its not such a great solution however you look at it. But at least this way its a bit safer.

CM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.