I want to have method - for example LogUtil.logCurrentMethod()
, which return parameters of method from which it is executed and their values.
For example :
public void temp(int first, String second, int third){
LogUtil.logCurrentMethod()
//something
}
and when I call :
temp(1, "2", 3);
to print:
first: 1
second: 2
third: 3
I want that, because it is really annoying to log all parameters of methods with 5 parameters for example. logCurrentMethod
can take parameters, the idea is to make logging easier. Another problem is that when I copy paste Log lines, I often don't change parameters names (so I have for example logged width and width instead of width and height or something like that). I can create new Object{}.getClass.getEnclosingMethod()
to get this method and to pass it to the method (and use Reflection
to take their names), but I don't know the values. Other approach is to pass parameters to log method and pass new Object{}.getClass.getEnclosingMethod()
, but I think there should be an easier and more convenient way.
Thanks in advance.