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
publicvoidserviceLog(){
3434
}
3535

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

52-
StringBufferclassAndMethod = newStringBuffer();
42+
StringBufferclassAndMethod = newStringBuffer();
5343

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

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

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

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

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

76-
longstart = System.currentTimeMillis();
77-
Objectresult = joinPoint.proceed();
78-
longtimeConsuming = 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-
returnresult;
82-
} catch (Throwablethrowable){
83-
log.error(throwable.getMessage(), throwable);
84-
}
85-
returnnull;
86-
}
68+
longstart = System.currentTimeMillis();
69+
Objectresult = joinPoint.proceed();
70+
longtimeConsuming = System.currentTimeMillis() - start;
8771

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

0 commit comments

Comments
(0)