53 lines
1.6 KiB
Java
53 lines
1.6 KiB
Java
package com.mattrixwv.cipherstream.aspect;
|
|
|
|
|
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
import org.slf4j.MDC;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@Slf4j
|
|
@Aspect
|
|
@Configuration
|
|
public class CipherStreamLoggingAspect{
|
|
public static final String CIPHER_NAME_LOGGING = "cipher";
|
|
|
|
|
|
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping) || @annotation(org.springframework.web.bind.annotation.PutMapping) || @annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.DeleteMapping)")
|
|
public void mappedFunction(){
|
|
//Intentionally blank
|
|
}
|
|
|
|
@Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
|
|
public void postFunction(){
|
|
//Intentionally blank
|
|
}
|
|
|
|
@Pointcut("execution(* com.mattrixwv.cipherstream.controller..*(..))")
|
|
public void cipherMethod(){
|
|
//Intentionally blank
|
|
}
|
|
|
|
@AfterReturning(pointcut = "cipherMethod() && postFunction()", returning = "returnedJson")
|
|
public void getCipherInfo(ObjectNode returnedJson){
|
|
//Extract JSON to MDC
|
|
returnedJson.fields().forEachRemaining(entry -> {
|
|
if(entry.getValue().isTextual()){
|
|
MDC.put(entry.getKey(), entry.getValue().asText());
|
|
}
|
|
else{
|
|
MDC.put(entry.getKey(), entry.getValue().toString());
|
|
}
|
|
});
|
|
|
|
//Print a log
|
|
log.info("CipherStream log");
|
|
}
|
|
}
|