Easy way to register parameter values ββin method exclusion methods in Java
Currently my exceptions are writing text and stack trace:
throw new RequestValidationException("test exception", parameters, e);
I want to collect all parameters for throws exception in all methods.
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("testparam", message.toString());
throw new RequestValidationException("test exception", parameters, e);
I am now using hashmap. I have to look at each method and check if it uses a parameter. It will cost me several days. There are thousands of exceptions in the code, is there an easy way to show the values?
+3
source to share
1 answer
You can use slf4j-ext for logging method parameters. They are logged at the trace level.
private static final XLogger xlogger = XLoggerFactory.getXLogger(MyClass.class);
Then you can use at the beginning and end of your methods like this:
protected void Method1(Message aMessage){
xLogger.entry(aMessage);
...
xLogger.exit();
}
+2
source to share