Skip to content

Commit eded3cd

Browse files
author
搜云库
authored
Update LogAspect.java
去掉 try catch
1 parent 71c189e commit eded3cd

File tree

1 file changed

+28
-41
lines changed
  • spring-boot-logback/src/main/java/io/ymq/logback/config/commons

1 file changed

+28
-41
lines changed

spring-boot-logback/src/main/java/io/ymq/logback/config/commons/LogAspect.java

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,43 @@ public class LogAspect {
3333
public void serviceLog() {
3434
}
3535

36-
@Around("serviceLog()")
37-
public Object around(ProceedingJoinPoint joinPoint) {
38-
try {
39-
40-
String requestUUID = MDC.get("requestUUID");
41-
if (requestUUID == null || "".equals(requestUUID)) {
42-
String uuid = UUID.randomUUID().toString();
43-
uuid = uuid.replaceAll("-", "").toUpperCase();
44-
MDC.put("requestUUID", uuid);
45-
log.info("around 在请求处理之前生成 logback requestUUID:{}", uuid);
46-
}
47-
48-
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
49-
Method method = signature.getMethod();
50-
Class<?> targetClass = method.getDeclaringClass();
36+
@Around("serviceLog()")
37+
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
38+
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
39+
Method method = signature.getMethod();
40+
Class<?> targetClass = method.getDeclaringClass();
5141

52-
StringBuffer classAndMethod = new StringBuffer();
42+
StringBuffer classAndMethod = new StringBuffer();
5343

54-
Log classAnnotation = targetClass.getAnnotation(Log.class);
55-
Log methodAnnotation = method.getAnnotation(Log.class);
44+
Log classAnnotation = targetClass.getAnnotation(Log.class);
45+
Log methodAnnotation = method.getAnnotation(Log.class);
5646

57-
if (classAnnotation != null) {
58-
if (classAnnotation.ignore()) {
59-
return joinPoint.proceed();
60-
}
61-
classAndMethod.append(classAnnotation.value()).append("-");
47+
if (classAnnotation != null) {
48+
if (classAnnotation.ignore()) {
49+
return joinPoint.proceed();
6250
}
51+
classAndMethod.append(classAnnotation.value()).append("-");
52+
}
6353

64-
if (methodAnnotation != null) {
65-
if (methodAnnotation.ignore()) {
66-
return joinPoint.proceed();
67-
}
68-
classAndMethod.append(methodAnnotation.value());
54+
if (methodAnnotation != null) {
55+
if (methodAnnotation.ignore()) {
56+
return joinPoint.proceed();
6957
}
58+
classAndMethod.append(methodAnnotation.value());
59+
}
7060

71-
String target = targetClass.getName() + "#" + method.getName();
72-
String params = JSONObject.toJSONStringWithDateFormat(joinPoint.getArgs(), dateFormat, SerializerFeature.WriteMapNullValue);
61+
String target = targetClass.getName() + "#" + method.getName();
7362

74-
log.info(STRING_START + "{} 开始调用--> {} 参数:{}", classAndMethod.toString(), target, params);
63+
String params = null;
64+
params = JSONObject.toJSONStringWithDateFormat(joinPoint.getArgs(), dateFormat, SerializerFeature.WriteMapNullValue);
7565

76-
long start = System.currentTimeMillis();
77-
Object result = joinPoint.proceed();
78-
long timeConsuming = System.currentTimeMillis() - start;
66+
log.info(STRING_START + "{} 开始调用--> {} 参数:{}", classAndMethod.toString(), target, params);
7967

80-
log.info("\n{} 调用结束<-- {} 返回值:{} 耗时:{}ms" + STRING_END, classAndMethod.toString(), target, JSONObject.toJSONStringWithDateFormat(result, dateFormat, SerializerFeature.WriteMapNullValue), timeConsuming);
81-
return result;
82-
} catch (Throwable throwable) {
83-
log.error(throwable.getMessage(), throwable);
84-
}
85-
return null;
86-
}
68+
long start = System.currentTimeMillis();
69+
Object result = joinPoint.proceed();
70+
long timeConsuming = System.currentTimeMillis() - start;
8771

72+
log.info("\n{} 调用结束<-- {} 返回值:{} 耗时:{}ms" + STRING_END, classAndMethod.toString(), target, JSONObject.toJSONStringWithDateFormat(result, dateFormat, SerializerFeature.WriteMapNullValue), timeConsuming);
73+
return result;
74+
}
8875
}

0 commit comments

Comments
 (0)