0

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.

BhushanK
  • 1,205
  • 6
  • 23
  • 39
DPM
  • 1,540
  • 2
  • 18
  • 40

1 Answers1

1

You can do this by two ways-

  1. By Using Interceptor-Logging With Interceptors

    Also refer this-Oracle Doc For Interceptor

  2. By Using AspectJ- Logging With AspectJ

    Refer this SO answer to know how to use AspectJ for logging purpose.

Community
  • 1
  • 1
Pankaj
  • 592
  • 7
  • 19