Skip to content

Commit

Permalink
Merge pull request #2 from leozhang123/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
leozhang123 committed Jun 23, 2020
2 parents eb13d8f + 8be8295 commit 0a21a2c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.leozhang123</groupId>
<artifactId>zaudit-spring-boot</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.2</version>
<packaging>pom</packaging>
<modules>
<module>zaudit-spring-boot-autoconfigure</module>
Expand Down
2 changes: 1 addition & 1 deletion zaudit-spring-boot-autoconfigure/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.github.leozhang123</groupId>
<artifactId>zaudit-spring-boot</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.2</version>
</parent>
<artifactId>zaudit-spring-boot-autoconfigure</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion zaudit-spring-boot-starter/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.github.leozhang123</groupId>
<artifactId>zaudit-spring-boot</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.2</version>
</parent>
<artifactId>zaudit-spring-boot-starter</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion zaudit/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.leozhang123</groupId>
<artifactId>zaudit-spring-boot</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.2</version>
</parent>
<artifactId>zaudit</artifactId>
<dependencies>
Expand Down
22 changes: 12 additions & 10 deletions zaudit/src/main/java/org/zl/log/audit/ZLogAspect.java
Expand Up @@ -17,7 +17,9 @@

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeSet;

Expand All @@ -34,8 +36,7 @@
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.lang.NonNull;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

Expand All @@ -61,19 +62,20 @@ public class ZLogAspect {

private boolean showRequestParameters;

@Autowired
private MessageSource messages;
ResourceBundle messages ;

public ZLogAspect(String loggerName, String[] protectParameters,String[] sessionAttributes,boolean showRequestParameters) {
this(loggerName,protectParameters);
public ZLogAspect(String loggerName, String[] protectParameters,@NonNull String[] sessionAttributes,boolean showRequestParameters) {
this.log = LoggerFactory.getLogger(loggerName);
this.protectParameters = protectParameters;
this.sessionAttributs = new TreeSet<>(Arrays.asList(sessionAttributes));
this.showRequestParameters = showRequestParameters;
this.showSession = !sessionAttributs.isEmpty();

messages = ResourceBundle.getBundle(this.getClass().getPackage().getName()+".messages", Locale.getDefault());
}

public ZLogAspect(String loggerName, String[] protectParameters) {
this.log = LoggerFactory.getLogger(loggerName);
this.protectParameters = protectParameters;
this(loggerName,protectParameters,new String[]{},false);
}

@Pointcut("@annotation(org.zl.log.audit.AuditLog)")
Expand Down Expand Up @@ -148,10 +150,10 @@ public void afterThrowing(JoinPoint joinPoint,Throwable ex) {
Method method = sign.getMethod();
AuditLog annotation = method.getAnnotation(AuditLog.class);
String desc = StringUtils.defaultIfEmpty(annotation.desc(), annotation.value());
log.info(logMessage("zaudit.log.failed"),desc,ex);
log.error(logMessage("zaudit.log.failed"),desc,ex);
}

String logMessage(String code) {
return messages.getMessage(code, null,null);
return messages.getString(code);
}
}

0 comments on commit 0a21a2c

Please sign in to comment.