Sign in to follow this  

Logging Issues

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

Hey, I'm trying to decide what approach to take with logging events on a program I'm working on, and there's heaps of possible options I could choose. Should I use a global object, a singleton class, or redirect cout/cerr/clog? Where should I store string messages? In a string table resource, as variables of a class, loaded from a file? What return values should I use - booleans for simplicity of logging (e.g. just "Success" or "Failure"), some sort of custom RESULT class, or through using exceptions?

Share this post


Link to post
Share on other sites
Quote:
Original post by SouthernMunk
Should I use a global object, a singleton class, or redirect cout/cerr/clog?


I suggest using several global objects (log channels) that you may disable on a per-channel basis.

Quote:

Where should I store string messages? In a string table resource, as variables of a class, loaded from a file?


Before, or after they are logged? Before they are logged, string literals would be enough. After they are logged, write them regularly to a file, and keep a dozen or so around in each channel (for instance, using a queue). Being able to display a log channel on top of the game as the game is running is excellent.

Quote:
What return values should I use - booleans for simplicity of logging (e.g. just "Success" or "Failure"), some sort of custom RESULT class, or through using exceptions?


If logging is important, throw exceptions, or possibly assert failures. If logging is unimportant, ignore failures (possibly issue a warning when the game starts). In any case, a call to a log function does not have a semantically sound return value.

Share this post


Link to post
Share on other sites
This is one of the questions that aspect oriented programming (AOP) tries to answer. The general idea is to move functionality that is needed in many classes out of the methods into it's own module. In other words, the methods would be unaware that they are being logged. I havn't used it myself, but it might be worth looking into.

Share this post


Link to post
Share on other sites

This topic is 4138 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this