Introduction

Logsystem is a page devoted to my logging code. By using a wordpress blog I can keep all changes, code and comments in one easily manageable place.

This new logging code is very easy to use, and can be extreemly simple or quite flexible and advanced.

Just how simple? Well, at the simplest all you have to do is to add log.cpp & log.hpp to your project, include them in each source file that wants to use logging and then just call:
log("Testing a log");

That’s it, a default “log.txt” file will be created, the comment will be saved to that and all logfiles will be closed when your program exits.

All logging uses the standard printf argument structure, so log(“Hello %s is %d”, name, age); would work normally.

So, that’s the very basics. What about if we want to do more advanced stuff?

With the exception of a special logd command for debugging logging, only the log command is used. So how does that work? Well, all commands to the logging are passed as bracketed codes such as [+], [clear] or [console].

So, if we called log in this way:
log("[file maingamelog]Testing!");

Then the logging code would open a file called maingamelog.txt and write Testing! to it.

Want to print to a console as well (and open one if developing in MSVC), then we use the code [console]. Note that this is an addition to the external text file being written.

Maybe we want to use html formatted code with different colours for the logging levels?
log("[file maingamelog][console][html]);

Now a maingamelog.html file is opened and written to..

Want to add a timestamp before each comment? Pass [timestamp] to turn this on. Want to pass debugging info and we are building in a debug mode, then pass [debugstamp].

There are currently quite a few codes, but hopefully you get the idea here.

See the [codes] tab at the top of this blog for a list of all the current codes.

Debugging:

Debugging logging is different than normal logging, because there is probably going to be a lot of it, and you don’t want any of it (nor any overhead) in the final release build. Therefore all debug logging is handled with a special logd command in this system. You can still pass all [codes] as normal though.

In a release build you would comment out the line:
#define LOG_PASS_DEBUG_INFO
In the log.hpp file, rebuild all and now all logd commands will compile away to comments. You cannot change to a debug level with the normal level [codes], so that you have to use only one method for debug logging.

07/03/08

New version uploaded. This adds a new [x] code, makes the html output use a nicer smaller verdana font, and adds a header line at the end of a logfile.

This blog is still in development and I will fill in the blanks as I go along.. 🙂


Latest

RSS