Indent qdebug output
-
Hi,
this is an awkward question: I've got a set of methods that calls each other and I'm using a set of qdebug outputs to follow the method call@void MyClass:myMethod(){
qDebug() << "[BEGIN] myMethod";
....
myOtherClassInstance->myMethod2();
qDebug() << "[END] myMethod";
}@This works great, but with a lot of methods on the stack it becomes a trouble to follow the stacktrace. Is there a simple and quick way to implement the method calls and the qdebug output? Otherwise, is there any other class that can help me obtaining such result?
Now my output looks like:@
[BEGIN] myMethod
[BEGIN] myMethod2
[END] myMethod2
[END] myMethod
@while I'd like something like:
@
[BEGIN] myMethod
[BEGIN] myMethod2
[END] myMethod2
[END] myMethod
@I guess this is not easily possible in C++ or without using AOP, but maybe Qt provides something like this....
The only solution that comes into my mind is to provide a wrapper around the qDebug that will track and increment the indentation each time I enter a method and will decrease every time I exit. -
The wrapper solution would have been my suggestion too. It doesn't sound too awkward.
-
10 years later I'll just leave it here ...
QDebug MyClass::qDebug1(int padding_width) { static QString s(" ");//placeholder QDebug ret = qDebug(); ret.noquote();//optional while(padding_width--) ret << s; return ret; }
so
@void MyClass:myMethod(){ qDebug1(1) << "[BEGIN] myMethod"; .... myOtherClassInstance->myMethod2();//qDebug1(2); qDebug(1) << "[END] myMethod"; }@
[BEGIN] myMethod [BEGIN] myMethod2 [END] myMethod2 [END] myMethod