I am writing custom log handler which will log events and will be used on top of controller methods like below,
@RecordEvent(authType = "EVENT", response = "", inputParams = "111")
@GetMapping(value = "getRoles", produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> getRoles(Authentication a, HttpServletRequest req,String test) {
test="ahdkjhasdkjhaskd";
................................
.................................
Map<String, Object> map = new HashMap<>();
return map;
}
package trinity.sso.logging;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RecordEvent {
String authType() ;
String inputParams() ;
String response() ;
}
@Aspect
@Component
public class EventLoggingComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(EventLoggingComponent.class);
private ExpressionParser expressionParser = new SpelExpressionParser();
private TemplateParserContext parserContext = new TemplateParserContext();
@Pointcut("@annotation(recordEvent)")
public void executeRecordEvent(RecordEvent recordEvent) {
}
@AfterReturning(pointcut = "executeRecordEvent(recordEvent)", returning = "result")
public void logEvent(JoinPoint joinPoint, RecordEvent recordEvent, Object result) {
//log here
}
}
So I wanted to make the response param in annotation as user defined where he can use combintation of response object template to form a string. Like response.get("status")+" is "+response.get("description")
. But how user can access direct response body like this or is there any alterntive to form string like this using response body and status code. it will be different for each method. So, user can define custom message using response body and status for each method.
Is there any method or alternative to achieve this?