Authored by zhengyouwei

app server

package com.ui.User;
import org.springframework.stereotype.Component;
/**
* Created by zhengyouwei on 2016/11/15.
*/
@Component
public class AppAuthLocal {
}
... ...
... ... @@ -12,9 +12,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
... ... @@ -29,6 +27,9 @@ public class UserAuthLocal {
private static ConcurrentHashMap<String, AuthModule> modulemap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, Set<String>> moduleGroupmap = new ConcurrentHashMap<>();
@Autowired
HttpRestClient httpRestClient;
... ... @@ -44,57 +45,73 @@ public class UserAuthLocal {
}
//加载mudule信息
BaseResponse<List<AuthModule>> moduleResponse = httpRestClient.exchangeForget(HttpUriContants.GET_All_MODULE, new ParameterizedTypeReference<BaseResponse<List<AuthModule>>>() {}, null);
BaseResponse<List<AuthModule>> moduleResponse = httpRestClient.exchangeForget(HttpUriContants.GET_All_MODULE, new ParameterizedTypeReference<BaseResponse<List<AuthModule>>>() {
}, null);
List<AuthModule> modulelist = moduleResponse.getData();
for (AuthModule module : modulelist) {
modulemap.put(module.getModuleName(), module);
}
//加载module组信息
for (Map.Entry<String,AuthModule> entry : modulemap.entrySet()){
AuthModule authModule = entry.getValue();
String group = authModule.getModuleGroup();
if (StringUtils.isNotBlank(group)){
if (moduleGroupmap.containsKey(group)){
moduleGroupmap.get(group).add(entry.getKey());
}else {
Set<String> groupSet = new HashSet<>();
groupSet.add(entry.getKey());
moduleGroupmap.put(group,groupSet);
}
}
}
}
/**
* jian quan
*
* @param user
* @param module
* @return
*/
public boolean auth(String user,String module){
if(usermap.isEmpty()){//改用延时加载
public boolean auth(String user, String module) {
if (usermap.isEmpty()) {//改用延时加载
init();
}
User u = usermap.get(user);
if (u == null){
if (u == null) {
return false;
}
AuthModule authModule = modulemap.get(module);
if (authModule == null){
if (authModule == null) {
return false;
}
//最高权限
if (StringUtils.isNotBlank(u.getModuleGroups())){
if (StringUtils.isNotBlank(u.getModuleGroups())) {
String[] moduleGroupArray = u.getModuleGroups().split(",");
for (String groupName:moduleGroupArray){
if ("all".equals(groupName)){
return true;
}
for (String groupName : moduleGroupArray) {
if ("all".equals(groupName)) {
return true;
}
}
}
//先查找group
String moduleGroup = authModule.getModuleGroup();
if (moduleGroup != null && StringUtils.isNotBlank(u.getModuleGroups())){
if (moduleGroup != null && StringUtils.isNotBlank(u.getModuleGroups())) {
String[] moduleGroupArray = u.getModuleGroups().split(",");
for (String groupName:moduleGroupArray){
if (moduleGroup.equals(groupName)){
for (String groupName : moduleGroupArray) {
if (moduleGroup.equals(groupName)) {
return true;
}
}
}
//在查找单一类
if (StringUtils.isNotBlank(u.getModules())){
if (StringUtils.isNotBlank(u.getModules())) {
String[] modulesArray = u.getModules().split(",");
for (String moduleName:modulesArray){
if (module.equals(moduleName)){
for (String moduleName : modulesArray) {
if (module.equals(moduleName)) {
return true;
}
}
... ... @@ -110,23 +127,50 @@ public class UserAuthLocal {
* @return
*/
public User getUserByname(String name) {
if(usermap.isEmpty()){//改用延时加载
if (usermap.isEmpty()) {//改用延时加载
init();
}
return usermap.get(name);
}
public AuthModule getAuthModuleByname(String name) {
if (modulemap.isEmpty()) {//改用延时加载
init();
}
return modulemap.get(name);
}
/**
* 获取用户
* 获取用户所有的权限
*
* @param name
* @return
*/
public AuthModule getAuthModuleByname(String name) {
if(modulemap.isEmpty()){//改用延时加载
public Set<String> getAllModuleByname(String name) {
Set<String> set = new HashSet<>();
if (usermap.isEmpty()) {//改用延时加载
init();
}
return modulemap.get(name);
User u = usermap.get(name);
String groups = u.getModuleGroups();
if (StringUtils.isNotBlank(groups)){//添加组
for (String group : groups.split(",")) {
if ("all".equals(group)){
set.addAll(modulemap.keySet());
return set;
}
set.addAll(moduleGroupmap.get(group));
}
}
//添加但模块
String modules = u.getModules();
if (StringUtils.isNotBlank(modules)){//添加组
for (String module : modules.split(",")) {
set.add(module);
}
}
return set;
}
/**
... ... @@ -141,9 +185,9 @@ public class UserAuthLocal {
BaseResponse<User> response = httpRestClient.exchangeForget(HttpUriContants.GET_USER_BY_NAME, new ParameterizedTypeReference<BaseResponse<User>>() {
}, map);
User user = response.getData();
if (user == null){
if (user == null) {
usermap.remove(name);
}else{
} else {
usermap.put(name, user);
}
}
... ... @@ -157,13 +201,26 @@ public class UserAuthLocal {
public void flushModule(String name) {
Map<String, String> map = new HashMap<>();
map.put("name", name);
AuthModule oldAuthModule = modulemap.get(name);
BaseResponse<AuthModule> response = httpRestClient.exchangeForget(HttpUriContants.MODULE_GET_BYNAME, new ParameterizedTypeReference<BaseResponse<AuthModule>>() {
}, map);
AuthModule authModule = response.getData();
if (authModule == null){
if (authModule == null) {
modulemap.remove(name);
}else{
//删除组里的模块
String group = oldAuthModule.getModuleGroup();
if (moduleGroupmap.containsKey(group)) {
moduleGroupmap.get(group).remove(name);
}
} else {
modulemap.put(name, authModule);
if (moduleGroupmap.containsKey(authModule.getModuleGroup())){
moduleGroupmap.get(authModule.getModuleGroup()).add(name);
}else {
Set<String> groupSet = new HashSet<>();
groupSet.add(name);
moduleGroupmap.put(authModule.getModuleGroup(),groupSet);
}
}
}
... ...
package com.ui.app.common;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by zhengyouwei on 2016/11/15.
*/
public class AppModule {
private static final Set<String> appModuleSet = new HashSet<>();
static {
appModuleSet.add("javaRestart");
}
public static String getAuthAppModule(Set<String> modules) {
StringBuilder stringBuilder = new StringBuilder();
for (String module : modules) {
if (appModuleSet.contains(module)) {
stringBuilder.append(module).append("|");
}
}
String result = stringBuilder.toString();
if (result.endsWith("|")){
return result.substring(0,result.length() - 1).toLowerCase();
}else {
return "";
}
}
}
... ...
package com.ui.app.common;
/**
* Created by zhengyouwei on 2016/11/15.
*/
public interface ErrorCode {
public static final int SYSTEM_ERROR = -200;
public static final String SYSTEM_ERROR_MESSAGE = "system error";
public static final int LOGIN_ERROR = -300;
public static final String LOGIN_ERROR_MESSAGE = "login failed";
public static final int TOKEN_ERROR = -301;
public static final String TOKEN_ERROR_MESSAGE = "token invalid";
public static final int AUTH_ERROR = -302;
public static final String AUTH_ERROR_MESSAGE = "auth failed";
public static final int PARAM_ERROR = -303;
public static final String PARAM_ERROR_MESSAGE = "param failed";
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/14.
*/
@Data
public class AppBaseReq {
private String accountname;
private String token;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/15.
*/
@Data
public class JavaRestartOperate extends AppBaseReq{
private String project;
private String operate;
private String[] ips;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/15.
*/
@Data
public class JavaRestartStatus extends AppBaseReq {
private String project;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/15.
*/
@Data
public class LoginReq extends AppBaseReq {
private String password;
}
... ...
package com.ui.app.resp;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/15.
*/
@Data
public class AccountInfo {
private String token;
private String accountname;
//(a|b|c 全小写)
private String privacy;
private String email;
private String cName;
private String mobile;
private String role;
}
... ...
... ... @@ -81,6 +81,11 @@ public class HttpUriContants {
public static final String USER_DELETE_NAME = "/user/deleteByName";
public static final String USER_OPERATE = "/user/operate";
public static final String APP_ADD_SEESION = "/user/appAddSession";
public static final String APP_GET_SEESION = "/user/appGetSession";
public static final String APP_REMOVE_SEESION = "/user/appRemoveSession";
/**
* module
... ... @@ -173,6 +178,10 @@ public class HttpUriContants {
public static final String JAVA_RESTART_STATAUS = "/javaRestart/getProjectStatus";
public static final String JAVA_STOP_RESTART = "/javaRestart/stopOrRestart";
public static final String JAVA_GET_MESSAGE = "/javaRestart/getMessage";
public static final String JAVA_RESTART_ALL = "/javaRestart/queryAll";
public static final String JAVA_STOP_APP = "/javaRestart/appExe";
//双中心切换
public static final String CENTERSWITCH_GET = "/centerSwitch/getSwitchList";
... ...
... ... @@ -24,7 +24,7 @@ public class ProjectOnline {
JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30"));
JAVA_LIST.add(new Project("1","yoho-push","137","yoho30"));
JAVA_LIST.add(new Project("1","cms_push","514","yoho30"));
JAVA_LIST.add(new Project("1","mars_push","494","yoho30"));
//JAVA_LIST.add(new Project("1","mars_push","494","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-shops","490","yoho30"));
JAVA_LIST.add(new Project("1","yoho-social","353","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30"));
... ...
package com.ui.ctrl.app;
import com.alibaba.fastjson.JSONObject;
import com.ui.User.UserAuthLocal;
import com.ui.app.common.ErrorCode;
import com.ui.app.req.AppBaseReq;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.project.Project;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import java.util.Set;
@Aspect
public class AppAspect {
private Logger log = LoggerFactory.getLogger("appLogger");
@Autowired
private HttpRestClient httpClient;
@Autowired
private UserAuthLocal userAuthLocal;
@Around("within(com.ui.ctrl.app.*Ctrl) && execution (@org.springframework.web.bind.annotation.RequestMapping * *.*(..))")
public Object appAspect(final ProceedingJoinPoint pjp) throws Throwable {
BaseResponse baseResponse = new BaseResponse();
Signature signature = pjp.getSignature();
String method = signature.getName();
try {
RequestMapping requestMapping = AnnotationUtils.findAnnotation(signature.getDeclaringType(), RequestMapping.class);
String path = requestMapping.value()[0];
String module = path.split("_")[1];
if (!"login".equals(module)) {//登录不管
Object[] paramsArray = pjp.getArgs();//参数
AppBaseReq appBaseReq = argsArrayToJson(paramsArray);
log.info(method + "--req--" + JSONObject.toJSONString(appBaseReq));
String accountname = appBaseReq.getAccountname();//用户名
String token = appBaseReq.getToken();//token
if (StringUtils.isBlank(accountname) || StringUtils.isBlank(token)) {
baseResponse.setCode(ErrorCode.PARAM_ERROR);
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse));
return baseResponse;
}
//校验token
BaseResponse<String> response = httpClient.defaultPost(HttpUriContants.APP_GET_SEESION + "?token=" + token, null, BaseResponse.class);
if (response == null) {//获取失败
baseResponse.setCode(ErrorCode.TOKEN_ERROR);
baseResponse.setMessage(ErrorCode.TOKEN_ERROR_MESSAGE);
log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse));
return baseResponse;
}
String redisAccountName = response.getData();
if (StringUtils.isBlank(redisAccountName) || !redisAccountName.equals(accountname)) {//token失效
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse));
return baseResponse;
}
//校验权限
Set<String> set = userAuthLocal.getAllModuleByname(accountname);
if (!set.contains(module)) {
baseResponse.setCode(ErrorCode.AUTH_ERROR);
baseResponse.setMessage(ErrorCode.AUTH_ERROR_MESSAGE);
log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse));
return baseResponse;
}
}
} catch (Exception e) {
log.error("AppAspect failed", e);
}
try {
Object result = pjp.proceed();
log.info(method + "--resp--" + JSONObject.toJSONString(result));
return result;
} catch (Exception e) {
log.error("AppAspect exe failed", e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse));
return baseResponse;
}
}
/**
* 请求参数拼装
*
* @param paramsArray
* @return
*/
private AppBaseReq argsArrayToJson(Object[] paramsArray) {
if (paramsArray != null && paramsArray.length > 0) {
AppBaseReq appBaseReq = (AppBaseReq) paramsArray[0];
return appBaseReq;
}
return null;
}
}
... ...
package com.ui.ctrl.app;
import com.alibaba.fastjson.JSON;
import com.ui.app.common.ErrorCode;
import com.ui.app.req.AppBaseReq;
import com.ui.app.req.JavaRestartOperate;
import com.ui.app.req.JavaRestartStatus;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.project.Project;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.LinkedList;
import java.util.List;
/**
* Created by zhengyouwei on 2016/11/14.
* app 服务端,重写一个
*/
@RestController
@RequestMapping(value = "/app_javaRestart")
public class AppJavaRestartCtrl {
Logger log = LoggerFactory.getLogger(AppJavaRestartCtrl.class);
@Autowired
private HttpRestClient httpClient;
/**
* 获取所有的项目
*
* @return
*/
@RequestMapping("/app_getprojectlist")
public BaseResponse getProjectList(@RequestBody AppBaseReq appBaseReq) {
BaseResponse baseResponse = new BaseResponse();
try {
BaseResponse<List<Project>> response = httpClient.exchangeForget(HttpUriContants.JAVA_RESTART_ALL, new ParameterizedTypeReference<BaseResponse<List<Project>>>() {
}, null);
List<String> stringList = new LinkedList<>();
if (response != null) {
for (Project project : response.getData()) {
stringList.add(project.getName());
}
}
baseResponse.setData(stringList);
} catch (Exception e) {
log.error("app javaRestart getProjectList error", e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
}
return baseResponse;
}
/**
* 获取项目的状态
*
* @return
*/
@RequestMapping("/app_getprojectdetail")
public BaseResponse getProjectDetail(@RequestBody JavaRestartStatus javaRestartStatus) {
BaseResponse baseResponse = new BaseResponse();
try {
BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_STATAUS + "?project=" + javaRestartStatus.getProject(), null, BaseResponse.class);
if (rep == null){
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
return baseResponse;
}else {
baseResponse.setData(rep.getData());
}
} catch (Exception e) {
log.error("app javaRestart getProjectDetail error", e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
}
return baseResponse;
}
/**
* 操作
*
* @return
*/
@RequestMapping("/app_operate")
public BaseResponse javaRestartOperate(@RequestBody JavaRestartOperate javaRestartOperate) {
BaseResponse baseResponse = new BaseResponse();
try {
if (StringUtils.isBlank(javaRestartOperate.getProject()) || StringUtils.isBlank(javaRestartOperate.getOperate()) || javaRestartOperate.getIps() == null ){
baseResponse.setCode(ErrorCode.PARAM_ERROR);
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
return baseResponse;
}
httpClient.defaultPost(HttpUriContants.JAVA_STOP_APP, javaRestartOperate, BaseResponse.class);
} catch (Exception e) {
log.error("app javaRestart getprojects error", e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
}
return baseResponse;
}
public static void main(String[] args) {
JavaRestartOperate javaRestartOperate = new JavaRestartOperate();
javaRestartOperate.setToken("FdHvfmnGrsGrWGFz");
javaRestartOperate.setAccountname("admin");
javaRestartOperate.setOperate("stop");
javaRestartOperate.setProject("yoho-gateway");
javaRestartOperate.setIps(new String[]{"172.168.1.1","172.165.1.1"});
System.out.println(JSON.toJSON(javaRestartOperate));
}
}
... ...
package com.ui.ctrl.app;
import com.ui.User.MD5Util;
import com.ui.User.UserAuthLocal;
import com.ui.app.common.AppModule;
import com.ui.app.common.ErrorCode;
import com.ui.app.req.AppBaseReq;
import com.ui.app.req.LoginReq;
import com.ui.app.resp.AccountInfo;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.User;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Set;
/**
* Created by zhengyouwei on 2016/11/14.
* app 服务端,重写一个
*/
@RestController
@RequestMapping(value = "/app_login")
public class AppLoginCtrl {
Logger log = LoggerFactory.getLogger(AppLoginCtrl.class);
@Autowired
private HttpRestClient httpClient;
@Autowired
private UserAuthLocal userAuthLocal;
/**
* 登录
* @param loginReq
* @return
*/
@RequestMapping("/app_login")
public BaseResponse login(@RequestBody LoginReq loginReq) {
BaseResponse baseResponse = new BaseResponse();
try {
User u = userAuthLocal.getUserByname(loginReq.getAccountname());
if (u == null) {
baseResponse.setCode(ErrorCode.LOGIN_ERROR);
baseResponse.setMessage("account not exist");
return baseResponse;
}
if (u.getPwd().equals(MD5Util.encryption(loginReq.getPassword()))) {//登录成功
//生成TOKEN
String token = RandomStringUtils.randomAlphabetic(16);
//记录token
httpClient.defaultPost(HttpUriContants.APP_ADD_SEESION + "?name=" + loginReq.getAccountname() + "&token=" + token, null, BaseResponse.class);
//返回信息
AccountInfo accountInfo = new AccountInfo();
accountInfo.setAccountname(loginReq.getAccountname());
accountInfo.setToken(token);
accountInfo.setCName(u.getCName());
accountInfo.setEmail(u.getEmail());
accountInfo.setMobile(u.getMobile());
accountInfo.setRole(u.getRole());
Set<String> authModules = userAuthLocal.getAllModuleByname(loginReq.getAccountname());
String privacy = AppModule.getAuthAppModule(authModules);
accountInfo.setPrivacy(privacy);
baseResponse.setData(accountInfo);
} else {
baseResponse.setCode(ErrorCode.LOGIN_ERROR);
baseResponse.setMessage("password error");
return baseResponse;
}
} catch (Exception e) {
log.error("app login error",e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
}
return baseResponse;
}
/**
* 登出
* @return
*/
@RequestMapping("/app_logout")
public BaseResponse logout(@RequestBody AppBaseReq appBaseReq) {
BaseResponse baseResponse = new BaseResponse();
try {
httpClient.defaultPost(HttpUriContants.APP_REMOVE_SEESION + "?token=" + appBaseReq.getToken(), null, BaseResponse.class);
} catch (Exception e) {
log.error("app logout error",e);
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE);
}
return baseResponse;
}
}
... ...
... ... @@ -16,7 +16,9 @@
<context:property-placeholder location="classpath:*.properties" />
<context:component-scan base-package="com.ui" />
<!-- 打开aop 注解 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:aspectj-autoproxy/>
<bean id="appAspect" class="com.ui.ctrl.app.AppAspect" />
<mvc:annotation-driven>
<mvc:message-converters>
... ... @@ -71,9 +73,12 @@
<mvc:exclude-mapping path="/script/**"/>
<mvc:exclude-mapping path="/sql_format/**"/>
<mvc:exclude-mapping path="/dashboard/**"/>
<mvc:exclude-mapping path="/app_login/**"/>
<mvc:exclude-mapping path="/app_javaRestart/**"/>
<bean class="com.ui.interceptor.AuthInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>
\ No newline at end of file
... ...
... ... @@ -11,7 +11,7 @@
<!-- 日志最大的历史 7天 -->
<property name="maxHistory" value="2"/>
<!-- 日志最大的文件大小 10MB-->
<property name="maxFileSize" value="10MB"/>
<property name="maxFileSize" value="30MB"/>
<!-- ConsoleAppender 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
... ... @@ -66,6 +66,29 @@
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="APP_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.home}/logs/app.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>
${catalina.home}/logs/app.%d{yyyy-MM-dd}.%i.log.gz
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>${maxFileSize}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- 日志最大的历史 60天 -->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level - %msg%n</pattern>
</encoder>
</appender>
<!-- root级别 DEBUG -->
<root level="INFO">
<!-- 控制台输出 -->
... ... @@ -75,4 +98,9 @@
<appender-ref ref="WARN" />
</root>
<logger name="appLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="APP_LOG"/>
</logger>
</configuration>
\ No newline at end of file
... ...