Hi
is it possible to get the current line number or method name as a variable similar to LastException?
I would like to standardize my logging, which is currently showing the current activity, but unfortunately the debug logger links to the line where the Log() method call is placed.
here are some example code snippets that I liked to use to have standardized debug output
any ideas?
thanks
marco
found this code snippet (see link), maybe it is useful
is it possible to get the current line number or method name as a variable similar to LastException?
I would like to standardize my logging, which is currently showing the current activity, but unfortunately the debug logger links to the line where the Log() method call is placed.
here are some example code snippets that I liked to use to have standardized debug output
any ideas?
thanks
marco
B4X:
Sub LogInfo(info As String)
Dim title As String = myActivity.Title
Log("ℹ️ " & title.touppercase & ": " & info)
End Sub
B4X:
Sub LogException
Dim message As String
Dim title As String = myActivity.Title
message = "❌ " & title.touppercase & ": " & LastException.Message
Log(message)
End Sub
found this code snippet (see link), maybe it is useful
B4X:
/**
* Get the method name for a depth in call stack. <br />
* Utility function
* @param depth depth in the call stack (0 means current method, 1 means call method, ...)
* @return method name
*/
public static String getMethodName(final int depth)
{
final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
//System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName());
// return ste[ste.length - depth].getMethodName(); //Wrong, fails for depth = 0
return ste[ste.length - 1 - depth].getMethodName(); //Thank you Tom Tresansky
}