I want to implement loggers in a C++ project that I am working on. I am wondering whether it would be better to implement a logger within each class individually, or to have a single logging interface and instantiate an instance of it in each class using the log4cxx libraries. I have a few loggers I would like to implement that would log events in existing classes.
In using a logging interface, I mean:
class Logger
{
private:
log4cxx::LoggerPtr firstLogger(log4cxx::Logger::getLogger("first.log"));
log4cxx::LoggerPtr secondLogger(log4cxx::Logger::getLogger("second.log"));
public:
virtual void writeLogMessage(log4cxx::LoggerPtd logger, std::string msg);
};
Is what I am doing by passing that LoggerPtr the right way of doing it? Because I need to be able to select which logger to use.
Also, if creating a logging interface is better, can someone suggest a good example where one can see the nitty gritty of how to implement such an interface using log4cxx? So, for example, what needs to be private and what needs to be public etc.