Two alternatives to Cheers and hth. - Alf's answer:
You could give the logger a name, if you need it more than once in a scope:
Logger& logger = Logger::GetInstance();
// ...
logger.Print("Hello, world");
Or you could make the logging methods static as well:
static void Logger::Print(const T &t) {
Logger::GetInstance().Print(t);
}
and then call them statically:
Logger::Print("Hello world!");
You could argue that for the client it should not matter if there actually is an instance or not - the constructor is private so they can't create their own instance anyway. So whether the static methods create an instance or not should be none of their concern. In this case, having a public method called GetInstance
actually exposes irrelevant implementation details.