Jump to content
  • Advertisement
Sign in to follow this  
SouthernMunk

Logging Issues

This topic is 4349 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!