I want to add a logging mechanism to my project but I am afraid to have logging code spread all over the place.
I thus had the idea of having only one class Logger responsible for writing relevant information into the log, and all the other classes A, B, ... having a Logger object and just calling the corresponding logging function in that one Logger class instead of implementing logging function in classes A, B, directly.
class A {
public:
Logger logger;
...
void foo {
...
logger.log(this);
}
};
...
class Logger {
public:
void log(A a);
void log(B b);
...
};
Is that considered good practice or what is a clean way of doing logging without cluttering the production code?