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

logging stuff

Started by invinate Aug 13, 2006 at 2:18 PM 0 replies 500+ views
Original Post
invinate
invinate
i'm a little confused about logging stuff. this is how i do logging: I have a main app class with pointers to other classes. Inside each of those other classes i have an ofstream object and a Logger class that does all the logging. Ofstream object is initialized from main app class and logger is initialized from this ofstream object. The benifit is that every class in main app class can have their own log file. The disadvantage is that every class needs to worry about dealing with logging which is not very good. Also there's this problem: if a class inside main app class has another class inside of it, this other class cannot use the logger. like so:

class App
{
  class Obj
  {
    Logger logg;
    class Obj2 {} * obj2; //obj2 cannot use logg
  } * obj;
};
How should i deal with all of this? Is having a logger object inside of every class the answer? I would like to know how to design effective logging classes. thanks!
CrazyCdn
CrazyCdn
Search these forums, there have been many discussions on this very topic.

I personaly implemented (we had a singleton going for a while) a global logger. It logs to any number of files. But the functions are global (in a namespace of course) so it's easy to use.

Basically most people do something like this:
Log::Get().Write(...)

Where mine is just:
Log(...)

Global functions are not evil :-)
"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Topic Locked

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

Sign in to reply to this topic.