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.. 🙂

4 Responses to “Introduction”


  1. 1 Robert LaBlanc March 9, 2008 at 12:01 am

    Hello!

    I think this Logging system is very brilliant. I like it very much and am using it in one of my recent projects. I think some things could be added, like optional buffering or direct writing to file. Or is that already incorporated? I am only using the basic commands right now.

    Anyway, just keep up this good work, I will certainly follow any development on this.

    With Regards,
    Robert LaBlanc.

  2. 2 happymonster March 9, 2008 at 8:01 am

    Hi Robert,

    At the moment if will flush the contents of the buffer out to the file after every log() statement. Someone else pointed out about perhaps making this optional as it is slower (but does print out the log in the event of a crash). So I think I will add two commands to turn this buffering on or off.

    I’m glad you like it! Thanks for your nice words..
    Richard

  3. 3 Marvin Wise April 23, 2008 at 12:59 pm

    Hi,

    Just wanted to let you know I am using this logging code in my stuff and it’s working out pretty well. Do you want me to put in some kind of acknowledgement somewhere in my programs about where I got it?

    Everything is working great so far. Thanks a lot for having this out here.

    WG

  4. 4 happymonster April 23, 2008 at 4:29 pm

    You are welcome. No need for any acknowledgements.. you can do what you want with the code.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s





%d bloggers like this: