com.github.lhnonline.boot.common.properties.RequestLogConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weboot-common Show documentation
Show all versions of weboot-common Show documentation
用于SpringBoot项目 | 接口返回数据包装,http状态码aop, http请求日志统一打印 | 使用了fastjson,和 mybatis-plus-extension
The newest version!
package com.github.lhnonline.boot.common.properties;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* author luohaonan
* date 2020-11-11
* email [email protected]
* description
*/
@Getter
@Setter
@Slf4j
@Component
@ConfigurationProperties(prefix = "weboot.log")
public class RequestLogConfig {
private String ignoreParamTypes = "org.springframework.validation.BeanPropertyBindingResult,";
private Boolean headerEnabled = Boolean.FALSE;
private Boolean headerAll = Boolean.FALSE;
private String headerNames = "host,token";
private Set ignoreTypeSet;
private Set logHeaderSet;
@PostConstruct
public void init() {
ignoreTypeSet = new LinkedHashSet<>();
logHeaderSet = new LinkedHashSet<>();
if (!StringUtils.isEmpty(ignoreParamTypes)) {
String[] paraTypes = ignoreParamTypes.split(",");
List clazz = Arrays.asList(paraTypes);
clazz.forEach(c -> {
try {
Class> aClass = Class.forName(c);
ignoreTypeSet.add(aClass);
} catch (ClassNotFoundException e) {
log.warn("skip unrecognized class type '{}' when config weboot.log.ignore-param-types", c);
}
});
}
if (headerEnabled && null != headerNames) {
String[] logHeaderArray = headerNames.split(",");
logHeaderSet.addAll(Arrays.asList(logHeaderArray));
}
}
public String toString() {
return JSON.toJSON(this).toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy