'What are the pros and cons of adding logs in each method for debug build? [closed]
I am working on an android application codebase where a programmer has properly logged each method. I found it extremely helpful to understand the application flow. This practice saved many debugging efforts to understand the current code flow to identify the buggy method.
So, I am curious about pros and cons of logging each method (Logs are for debug build type only).
Thanks
Solution 1:[1]
It is quite efficient but at specific instances,taking that there are multiple threads it would actually cause devastating effect to system resources especially if you're logging to a single file. But that can be solved by reducing the logging to specific threads which can be switched at runtime.
my implementation would be:-
class Tracer{
void informCall(Object...callArgs){
meth=TraceUtils.getPreviousMethod();
if(noCondition||tracerCodition.trace(Trace.getCallerStackTraceElement())){
//since trace method can know which thread we are in that is not a necessary argument
TraceLogger.inform(TraceType.Method,meth.traceString()+"/nargs:/n"+TraceUtils.argsString(callArgs));
}
}
}
Note: specifying a condition for tracing increases the efficiency of debugging and also concentrates the search at specific points for example maybe a method under tracing is set to execute till a certain condition is reached if this particular method terminates too fast then it will mean that tracing will not be efficient especially in a situation where there is an intentional race condition of resources or logs are written to file but setting a trace condition to trace only a specific number of calls of a method or at certain intervals of time it would help increase efficiency.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | D. Sikilai |
