class MyMethodLogger
{
std::string _methodName;
public:
MyMethodLogger(const char *methodName):
_methodName(methodName)
{
log << "Entering method " << _methodName << std::endl;
}
~MyMethodLogger()
{
log << "Exiting method " << _methodName << std::endl;
}
};
Very easy to use: just instance a MyMethodLogger as the first instruction in method body:
void method()
{
MyMethodLogger("method()");
...
}
At the end of the method execution (of after an exception throw) the destructor of MyMethodLogger will trace the exit from the method.
Nessun commento:
Posta un commento