logging - Create log method to log parameters and their values on current executing method in java -


i want have method - example logutil.logcurrentmethod(), return parameters of method executed , values. example :

public void temp(int first, string second, int third){     logutil.logcurrentmethod()    //something } 

and when call :

temp(1, "2", 3); 

to print:

first: 1 second: 2 third: 3 

i want that, because annoying log parameters of methods 5 parameters example. logcurrentmethod can take parameters, idea make logging easier. problem when copy paste log lines, don't change parameters names (so have example logged width , width instead of width , height or that). can create new object{}.getclass.getenclosingmethod() method , pass method (and use reflection take names), don't know values. other approach pass parameters log method , pass new object{}.getclass.getenclosingmethod(), think there should easier , more convenient way.
in advance.

you can 2 ways-

  1. by using interceptor-logging interceptors

    also refer this-oracle doc interceptor

  2. by using aspectj- logging aspectj

    refer so answer know how use aspectj logging purpose.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -