在AWS CloudWatch上打印切入点属性的空值



这些是AWS CloudWatch日志,我在其中获取null值(无论如何,获取包、类、方法名(:

2021-05-10 04:27:36.707  INFO 1 --- [nio-8080-exec-3] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]
2021-05-10 04:27:36.707 INFO 1 --- [nio-8080-exec-3] t.o.platform.advice.LoggingAdvice : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]
2021-05-10T09:57:36.710+05:30 Copy
2021-05-10 04:27:36.710  INFO 1 --- [nio-8080-exec-2] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.controller.PlatformController : getPlatform()arguments : [ null, null, null, null, {}, null ]
2021-05-10 04:27:36.710 INFO 1 --- [nio-8080-exec-2] t.o.platform.advice.LoggingAdvice : method invoked class tech.onesilverbullet.platform.controller.PlatformController : getPlatform()arguments : [ null, null, null, null, { }, null ]
2021-05-10T09:57:36.711+05:30 Copy
2021-05-10 04:27:36.711  INFO 1 --- [nio-8080-exec-2] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]
2021-05-10 04:27:36.711 INFO 1 --- [nio-8080-exec-2] t.o.platform.advice.LoggingAdvice : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]
2021-05-10T09:57:36.711+05:30 Copy
2021-05-10 04:27:36.711  INFO 1 --- [nio-8080-exec-1] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]
2021-05-10 04:27:36.711 INFO 1 --- [nio-8080-exec-1] t.o.platform.advice.LoggingAdvice : method invoked class tech.onesilverbullet.platform.service.PlatformService : getKeyAndSecret()arguments : [ null ]

生成日志的Spring Boot代码(使用AOP(:

package tech.onesilverbullet.platform.advice;
import java.util.HashMap;
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* In this class, the logic for creating the logs is written.
*/
@Aspect
@Component
public class LoggingAdvice {
Map<String, String> map = new HashMap<String, String>();
LoggingAdvice() {
map.put("getUserFromToken", "A AUTHENTICATION");
map.put("doEntitlementCheck", "H ENTITLEMENT CHECK");
map.put("getProducer", "G API SELECTION");
map.put("callProducerApi", "M API CALL");
}
Logger log = LoggerFactory.getLogger(LoggingAdvice.class);
/**
* In this class, using @Pointcut which gives information where our logging
* mechanism will be implemented. SYNTAX - @Pointcut(vale =
* "execution(returnType
* RootDirectoryPath.packageName.className.methodName(no.of arguments))")
*/
@Pointcut(value = "execution(* tech.onesilverbullet.platform.*.*.*(..) )")
public void myPointcut() {
}
/**
* In this method we are passing ProceedingJoinPoint which is coming from AOP.
* 
* @param pjp - ProceedingJoinPoint internally uses the reflection by which we
*            can track the method called and also the details like, input
*            parameters which are coming to that particular method.
* @returns an object for the response in JSON.
* @throws Throwable
*/
@Around("myPointcut()")
public Object applicationLogger(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.currentTimeMillis();
ObjectMapper mapper = new ObjectMapper();
String methodName = pjp.getSignature().getName();
String className = pjp.getTarget().getClass().toString();
Object[] array = pjp.getArgs();
log.info("method invoked " + className + " : " + methodName + "()" + "arguments : "
+ mapper.writerWithDefaultPrettyPrinter().writeValueAsString(array));
Object object = pjp.proceed();
String getStepId = map.get(methodName);
long endTime = System.currentTimeMillis();
log.info(className + " : " + methodName + "()" + "response : " + object + "StepId : " + getStepId
+ " Execution Time : " + (endTime - startTime) + " ms");
return object;
}
}

我在本地获取的日志。我在本地看到所有东西,但在AWS CloudWatch上看不到:

getKeyAndSecret()response : [Ljava.lang.String;@6fd2fb0StepId : null Execution Time : 2 ms
2021-05-07 16:43:01.926  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : getUserFromToken()arguments : [ "abcduoieau", "kuhoahiwad" ] -- this method is also not showing on AWS but showing locally
2021-05-07 16:43:01.926  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.repository.PlatformRepository : getUserByToken()arguments : [ "abcduoieau", "kuhoahiwad" ]
2021-05-07 16:43:02.574  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.repository.PlatformRepository : getUserByToken()response : Consumer(apiKey=abcduoieau, apiSecret=kuhoahiwad, consumerId=kedar1023)StepId : null Execution Time : 648 ms
2021-05-07 16:43:02.574  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.service.PlatformService : getUserFromToken()response : Consumer(apiKey=abcduoieau, apiSecret=kuhoahiwad, consumerId=kedar1023)StepId : A AUTHENTICATION Execution Time : 648 ms
2021-05-07 16:43:02.575  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : doEntitlementCheck()arguments : [ "kedar1023", "insurance", "literm", "v1", "customer" ]
2021-05-07 16:43:02.577  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.repository.PlatformRepository : getUserDetails()arguments : [ "kedar1023", "literm" ]
2021-05-07 16:43:02.640  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.repository.PlatformRepository : getUserDetails()response : ConsumerEntitlement(consumerId=kedar1023, category=insurance, apiId=literm, versionId=v1)StepId : null Execution Time : 64 ms
2021-05-07 16:43:02.640  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.service.PlatformService : doEntitlementCheck()response : ConsumerEntitlement(consumerId=kedar1023, category=insurance, apiId=literm, versionId=v1)StepId : H ENTITLEMENT CHECK Execution Time : 66 ms
2021-05-07 16:43:02.641  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.PlatformService : getProducer()arguments : [ "literm", "v1" ]
2021-05-07 16:43:02.642  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.repository.PlatformRepository : getProducerDetails()arguments : [ "literm", "v1" ]
2021-05-07 16:43:02.740  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.repository.PlatformRepository : getProducerDetails()response : Provider(apiId=literm, typeOfRequest=GET, apiVersion=v1, typeOfApi=REST, url=https://jni1ik9z9d.execute-api.ap-south-1.amazonaws.com/dev/insurance/literm/v1/getquotes)StepId : null Execution Time : 99 ms
2021-05-07 16:43:02.740  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.service.PlatformService : getProducer()response : Provider(apiId=literm, typeOfRequest=GET, apiVersion=v1, typeOfApi=REST, url=https://jni1ik9z9d.execute-api.ap-south-1.amazonaws.com/dev/insurance/literm/v1/getquotes)StepId : G API SELECTION Execution Time : 100 ms
2021-05-07 16:43:02.741  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : method invoked class tech.onesilverbullet.platform.service.RestService : callProducerApi()arguments : [ "https://jni1ik9z9d.execute-api.ap-south-1.amazonaws.com/dev/insurance/literm/v1/getquotes" ]
2021-05-07 16:43:03.762  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.service.RestService : callProducerApi()response : {"name": "Divyanka Kumari", "birthday": "8-2-1991", "gender": "female", "employed": "true", "address": "Uttrakhand", "maritalStatus": "single", "phone no.": "9096426545"}StepId : M API CALL Execution Time : 1021 ms
2021-05-07 16:43:03.763  INFO 17856 --- [nio-8080-exec-5] t.o.platform.advice.LoggingAdvice        : class tech.onesilverbullet.platform.controller.PlatformController : getPlatform()response : {"name": "Divyanka Kumari", "birthday": "8-2-1991", "gender": "female", "employed": "true", "address": "Uttrakhand", "maritalStatus": "single", "phone no.": "9096426545"}StepId : null Execution Time : 1870 ms

我的猜测是该方面没有问题,但您试图记录的信息是从生产或预生产服务器上的日志中剥离出来的,其中包含真实的客户数据。在许多受监管的行业,比如银行业,这种事情是一项硬性要求。看看你试图访问的内容:

  • getKeyAndSecret():听起来像是试图访问高度机密的信息
  • getPlatform():在第二个日志中打印个人用户数据

当然,我可能错了,因为这里只显示了一个方面,没有显示应用程序代码。另一种可能性是mapper.writerWithDefaultPrettyPrinter().writeValueAsString(array)中的某个地方存在错误。

最新更新