commit
8034e9ab87
13 changed files with 664 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||||
|
HELP.md |
||||
|
target/ |
||||
|
!.mvn/wrapper/maven-wrapper.jar |
||||
|
!**/src/main/**/target/ |
||||
|
!**/src/test/**/target/ |
||||
|
|
||||
|
### STS ### |
||||
|
.apt_generated |
||||
|
.classpath |
||||
|
.factorypath |
||||
|
.project |
||||
|
.settings |
||||
|
.springBeans |
||||
|
.sts4-cache |
||||
|
|
||||
|
### IntelliJ IDEA ### |
||||
|
.idea |
||||
|
*.iws |
||||
|
*.iml |
||||
|
*.ipr |
||||
|
|
||||
|
### NetBeans ### |
||||
|
/nbproject/private/ |
||||
|
/nbbuild/ |
||||
|
/dist/ |
||||
|
/nbdist/ |
||||
|
/.nb-gradle/ |
||||
|
build/ |
||||
|
!**/src/main/**/build/ |
||||
|
!**/src/test/**/build/ |
||||
|
|
||||
|
### VS Code ### |
||||
|
.vscode/ |
||||
|
|
||||
|
### logs ### |
||||
|
logs/ |
||||
@ -0,0 +1,59 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<groupId>bc.core</groupId> |
||||
|
<artifactId>bcmail</artifactId> |
||||
|
<version>1.0.01</version> |
||||
|
|
||||
|
<!-- 指定版本--> |
||||
|
<properties> |
||||
|
<java.version>1.8</java.version> |
||||
|
<springboot.version>2.7.15</springboot.version> |
||||
|
</properties> |
||||
|
|
||||
|
<!-- 依赖--> |
||||
|
<dependencies> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||
|
<version>${springboot.version}</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-mail</artifactId> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>commons-lang</groupId> |
||||
|
<artifactId>commons-lang</artifactId> |
||||
|
<version>2.6</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>commons-logging</groupId> |
||||
|
<artifactId>commons-logging</artifactId> |
||||
|
<version>1.2</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba</groupId> |
||||
|
<artifactId>fastjson</artifactId> |
||||
|
<version>2.0.7</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.amqp</groupId> |
||||
|
<artifactId>spring-rabbit-test</artifactId> |
||||
|
<scope>test</scope> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
<!--打包选项--> |
||||
|
<build> |
||||
|
<plugins> |
||||
|
<plugin> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
</build> |
||||
|
|
||||
|
</project> |
||||
@ -0,0 +1,12 @@ |
|||||
|
package bc.core.bcmail; |
||||
|
|
||||
|
import org.springframework.boot.SpringApplication; |
||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
|
||||
|
@SpringBootApplication |
||||
|
public class BcmailApplication { |
||||
|
public static void main(String[] args) { |
||||
|
SpringApplication.run(BcmailApplication.class, args); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package bc.core.bcmail.controller; |
||||
|
|
||||
|
|
||||
|
import org.apache.commons.lang.StringUtils; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
|
||||
|
@RestController |
||||
|
public class DebugController { |
||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
|
/*** |
||||
|
* 调试接口 |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping("/test") |
||||
|
public String mtest(String param){ |
||||
|
Date now = new Date(); |
||||
|
String nstr = sdf.format(now); |
||||
|
|
||||
|
// long timestamp = System.currentTimeMillis();
|
||||
|
String ret = ""; |
||||
|
if(StringUtils.isEmpty(param)){ |
||||
|
ret = nstr; |
||||
|
// ret = String.valueOf(timestamp);
|
||||
|
}else { |
||||
|
ret = param+"\r\n"+nstr; |
||||
|
} |
||||
|
return ret; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,75 @@ |
|||||
|
package bc.core.bcmail.controller; |
||||
|
|
||||
|
|
||||
|
import bc.core.bcmail.exception.AccessException; |
||||
|
import bc.core.bcmail.exception.BcException; |
||||
|
import bc.core.bcmail.utils.AjaxResult; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.web.bind.annotation.ControllerAdvice; |
||||
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
import org.springframework.web.bind.annotation.ResponseStatus; |
||||
|
|
||||
|
/** |
||||
|
* 全局异常控制器 |
||||
|
*/ |
||||
|
@ControllerAdvice |
||||
|
public class GlobalErrorController { |
||||
|
//日志初始化
|
||||
|
private static final Log log = LogFactory.getLog(GlobalErrorController.class); |
||||
|
|
||||
|
private JSONObject jsonObject=new JSONObject(); |
||||
|
/** |
||||
|
* 异常信息输出 |
||||
|
* @return |
||||
|
*/ |
||||
|
@ExceptionHandler(BcException.class) |
||||
|
@ResponseBody |
||||
|
public JSONObject aisHandler(BcException chex){ |
||||
|
jsonObject = AjaxResult.exception(chex.getCode(),chex.getMsg()); |
||||
|
return jsonObject; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 空指针异常 |
||||
|
* @param e |
||||
|
* @return |
||||
|
*/ |
||||
|
@ExceptionHandler(value =NullPointerException.class) |
||||
|
@ResponseBody |
||||
|
public JSONObject exceptionHandler(NullPointerException e){ |
||||
|
log.error("空指针异常:"+e.getStackTrace()); |
||||
|
String msg = e.getMessage()==null?"module not found!":e.getMessage(); |
||||
|
jsonObject.put("status",500); |
||||
|
jsonObject.put("message",msg); |
||||
|
return jsonObject; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 常规异常信息 |
||||
|
* @param ex |
||||
|
* @return |
||||
|
*/ |
||||
|
@ExceptionHandler(value = Exception.class) |
||||
|
@ResponseBody |
||||
|
public JSONObject exceptionHandler(Exception ex){ |
||||
|
log.error("异常信息:"+ex); |
||||
|
return AjaxResult.exception(500,ex.getMessage()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 401 异常 |
||||
|
* @param ae |
||||
|
* @return |
||||
|
*/ |
||||
|
@ResponseBody |
||||
|
@ResponseStatus(value = HttpStatus.UNAUTHORIZED) |
||||
|
@ExceptionHandler(value = AccessException.class) |
||||
|
public JSONObject accessHandler(AccessException ae){ |
||||
|
log.error("需要登录"+ae.getLocalizedMessage()); |
||||
|
return AjaxResult.exception(401,ae.getMessage()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
package bc.core.bcmail.controller; |
||||
|
|
||||
|
import bc.core.bcmail.utils.AjaxResult; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.time.ZoneId; |
||||
|
import java.time.ZonedDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.Date; |
||||
|
import java.util.LinkedHashMap; |
||||
|
import java.util.Map; |
||||
|
import java.util.TimeZone; |
||||
|
|
||||
|
@RestController |
||||
|
public class HomeController { |
||||
|
/** |
||||
|
* homepage |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping({"/",""}) |
||||
|
public JSONObject home(){ |
||||
|
// output current time
|
||||
|
// ask jdk gt 1.8+
|
||||
|
// // get localtime
|
||||
|
// ZoneId zoneId = ZoneId.of("America/New_York");
|
||||
|
// // get current time
|
||||
|
// ZonedDateTime zonedDateTime = ZonedDateTime.now();
|
||||
|
// // convert to US. time format
|
||||
|
// ZonedDateTime ustime = zonedDateTime.withZoneSameInstant(zoneId);
|
||||
|
// //
|
||||
|
// DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
//
|
||||
|
// String format = zonedDateTime .format(dateFormat);
|
||||
|
// return AjaxResult.success(format);
|
||||
|
//*************************************************************
|
||||
|
|
||||
|
// 设置时区为美国
|
||||
|
TimeZone timeZone = TimeZone.getTimeZone("America/New_York"); |
||||
|
// 创建 SimpleDateFormat 对象,指定日期格式
|
||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzzz"); |
||||
|
sdf.setTimeZone(timeZone); |
||||
|
|
||||
|
// 获取当前时间
|
||||
|
Date date = new Date(); |
||||
|
|
||||
|
// 将日期按照指定格式转换成字符串
|
||||
|
String formattedDate = sdf.format(date); |
||||
|
return AjaxResult.success(formattedDate); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/debug/{msg}") |
||||
|
public JSONObject debug(@PathVariable String msg){ |
||||
|
LinkedHashMap rtmap = new LinkedHashMap(); |
||||
|
rtmap.put("time",System.currentTimeMillis()); |
||||
|
rtmap.put("data",msg); |
||||
|
return AjaxResult.success("success",rtmap); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package bc.core.bcmail.controller; |
||||
|
|
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* |
||||
|
* |
||||
|
获取参数,并发送邮件,将结果post 给notify_url |
||||
|
json 传递的值用post方式 |
||||
|
*/ |
||||
|
@RestController |
||||
|
public class SendMailController { |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package bc.core.bcmail.exception; |
||||
|
|
||||
|
/** |
||||
|
* 访问权限异常 |
||||
|
*/ |
||||
|
public class AccessException extends RuntimeException{ |
||||
|
private String message; |
||||
|
|
||||
|
@Override |
||||
|
public String getMessage() { |
||||
|
return message; |
||||
|
} |
||||
|
|
||||
|
public void setMessage(String message) { |
||||
|
this.message = message; |
||||
|
} |
||||
|
|
||||
|
// 构造函数
|
||||
|
public AccessException(String message) { |
||||
|
this.message = message; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package bc.core.bcmail.exception; |
||||
|
|
||||
|
/** |
||||
|
* 全局异常 |
||||
|
*/ |
||||
|
public class BcException extends RuntimeException { |
||||
|
private String msg; |
||||
|
private int code; |
||||
|
|
||||
|
public String getMsg() { |
||||
|
return msg; |
||||
|
} |
||||
|
|
||||
|
public void setMsg(String msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
|
||||
|
public int getCode() { |
||||
|
return code; |
||||
|
} |
||||
|
|
||||
|
public void setCode(int code) { |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public BcException(String msg, int code) { |
||||
|
this.msg = msg; |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public BcException(String msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
package bc.core.bcmail.utils; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
|
||||
|
public class AjaxResult { |
||||
|
/** |
||||
|
* 接口返回数据 |
||||
|
* @param msg |
||||
|
* @param dataList |
||||
|
* @return |
||||
|
*/ |
||||
|
public static JSONObject success(String msg,List dataList){ |
||||
|
JSONObject result = new JSONObject(); |
||||
|
result.put("status",200); |
||||
|
result.put("msg",msg); |
||||
|
result.put("data",dataList); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static JSONObject success(String token){ |
||||
|
JSONObject result= new JSONObject(); |
||||
|
result.put("code",200); |
||||
|
result.put("token",token); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static JSONObject success(String msg, Map map){ |
||||
|
JSONObject result = new JSONObject(); |
||||
|
result.put("code",200); |
||||
|
result.put("msg",msg); |
||||
|
result.put("data",map); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 异常信息 |
||||
|
* @param msg |
||||
|
* @return |
||||
|
*/ |
||||
|
public static JSONObject error(String msg){ |
||||
|
JSONObject result = new JSONObject(); |
||||
|
result.put("code",500); |
||||
|
result.put("msg",msg); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 格式异常返回 |
||||
|
* @param code |
||||
|
* @param msg |
||||
|
* @return |
||||
|
*/ |
||||
|
public static JSONObject exception(int code,String msg){ |
||||
|
Map rmap = new HashMap(); |
||||
|
rmap.put("message",msg); |
||||
|
rmap.put("time",System.currentTimeMillis()/1000l); |
||||
|
|
||||
|
//
|
||||
|
JSONObject rjson = new JSONObject(); |
||||
|
rjson.put("status",code); |
||||
|
rjson.put("message",msg); |
||||
|
// rjson.put("data",rmap);
|
||||
|
|
||||
|
return rjson; |
||||
|
} |
||||
|
|
||||
|
public static JSONObject error500(String msg){ |
||||
|
Map rmap = new HashMap(); |
||||
|
rmap.put("message",msg); |
||||
|
//
|
||||
|
JSONObject rjson = new JSONObject(); |
||||
|
rjson.put("data",rmap); |
||||
|
rjson.put("status",500); |
||||
|
return rjson; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
# logback日志操作 |
||||
|
logging.config=classpath:logback-spring.xml |
||||
|
logging.path=./logs/ |
||||
|
|
||||
|
#application.properties基本配置,后面我都使用此配置来发送邮件 |
||||
|
## 基本配置 |
||||
|
### smtp服务器主机(163的) |
||||
|
spring.mail.host=smtp.163.com |
||||
|
### 连接邮件服务器端口(默认SMTP 25 POP 110) |
||||
|
spring.mail.port=25 |
||||
|
### 服务协议SMTP(代表是发送邮件) |
||||
|
spring.mail.protocol=smtp |
||||
|
### 登录服务器邮箱账号 |
||||
|
spring.mail.username=antladdie |
||||
|
### 登录服务器邮箱授权码(不是邮箱密码,这个是我们开通SMTP、POP时得到的授权码) |
||||
|
spring.mail.password=xxxxxxxxxxxxx |
||||
|
### 默认邮件的编码集(MimeMessage 编码,默认UTF-8) |
||||
|
spring.mail.default-encoding=UTF-8 |
||||
|
|
||||
|
# 补充配置(这里具体可以参照Jakarta Mail的扩展配置) |
||||
|
## 默认发送方邮箱账号(当程序未指定发件人邮箱则默认取这个) |
||||
|
#spring.mail.properties.mail.smtp.from=antladdie@163.com |
||||
|
## 开启权限认证 |
||||
|
spring.mail.properties.mail.smtp.auth=true |
||||
|
## 邮件接收时间的限制 |
||||
|
spring.mail.properties.mail.smtp.timeout=60000 |
||||
|
## 连接时间的限制 |
||||
|
spring.mail.properties.mail.smtp.connectiontimeout=60000 |
||||
|
## 邮件发送时间的限制(毫秒) |
||||
|
spring.mail.properties.mail.smtp.writetimeout=60000 |
||||
|
## 日志打印,邮件发送过程的日志会被输出 |
||||
|
spring.mail.properties.mail.debug=true |
||||
@ -0,0 +1,4 @@ |
|||||
|
===== Welcome to BCMIS ===== |
||||
|
SPB. version:${spring-boot.version} |
||||
|
BCMIS version 1.0.1 |
||||
|
============================ |
||||
@ -0,0 +1,199 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 --> |
||||
|
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true --> |
||||
|
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 --> |
||||
|
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --> |
||||
|
<configuration scan="true" scanPeriod="10 seconds"> |
||||
|
|
||||
|
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />--> |
||||
|
|
||||
|
<contextName>logback</contextName> |
||||
|
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 --> |
||||
|
<!--<property name="logging.path" value="${logging.path}" />--> |
||||
|
<!--<springProfile name="logging.path" scope="context" source="project.log.path" defaultValue="./aislogs/"/>--> |
||||
|
<springProperty name="LOG_PATH" source="logging.path" defaultValue="/home/chjyj/logs" /> |
||||
|
|
||||
|
|
||||
|
<!-- 彩色日志 --> |
||||
|
<!-- 彩色日志依赖的渲染类 --> |
||||
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> |
||||
|
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> |
||||
|
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> |
||||
|
<!-- 彩色日志格式 --> |
||||
|
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> |
||||
|
|
||||
|
|
||||
|
<!--输出到控制台--> |
||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> |
||||
|
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> |
||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
||||
|
<level>info</level> |
||||
|
</filter> |
||||
|
<encoder> |
||||
|
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern> |
||||
|
<!-- 设置字符集 --> |
||||
|
<charset>UTF-8</charset> |
||||
|
</encoder> |
||||
|
</appender> |
||||
|
|
||||
|
|
||||
|
<!--输出到文件--> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 DEBUG 日志 --> |
||||
|
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${LOG_PATH}/log_debug.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 日志归档 --> |
||||
|
<fileNamePattern>${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录debug级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>debug</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 INFO 日志 --> |
||||
|
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${LOG_PATH}/log_info.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 每天日志归档路径以及格式 --> |
||||
|
<fileNamePattern>${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录info级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>info</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 WARN 日志 --> |
||||
|
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${LOG_PATH}/log_warn.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<fileNamePattern>${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录warn级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>warn</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
|
||||
|
<!-- 时间滚动输出 level为 ERROR 日志 --> |
||||
|
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${LOG_PATH}/log_error.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<fileNamePattern>${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录ERROR级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>ERROR</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- |
||||
|
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、 |
||||
|
以及指定<appender>。<logger>仅有一个name属性, |
||||
|
一个可选的level和一个可选的addtivity属性。 |
||||
|
name:用来指定受此logger约束的某一个包或者具体的某一个类。 |
||||
|
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF, |
||||
|
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。 |
||||
|
如果未设置此属性,那么当前logger将会继承上级的级别。 |
||||
|
addtivity:是否向上级logger传递打印信息。默认是true。 |
||||
|
--> |
||||
|
<!--<logger name="org.springframework.web" level="info"/>--> |
||||
|
<!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>--> |
||||
|
<!-- |
||||
|
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作: |
||||
|
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息 |
||||
|
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别: |
||||
|
--> |
||||
|
|
||||
|
|
||||
|
<!-- |
||||
|
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性 |
||||
|
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF, |
||||
|
不能设置为INHERITED或者同义词NULL。默认是DEBUG |
||||
|
可以包含零个或多个元素,标识这个appender将会添加到这个logger。 |
||||
|
--> |
||||
|
|
||||
|
<!--开发环境:打印控制台--> |
||||
|
<springProfile name="dev"> |
||||
|
<logger name="com.nmys.view" level="debug"/> |
||||
|
</springProfile> |
||||
|
|
||||
|
<root level="info"> |
||||
|
<appender-ref ref="CONSOLE" /> |
||||
|
<appender-ref ref="DEBUG_FILE" /> |
||||
|
<appender-ref ref="INFO_FILE" /> |
||||
|
<appender-ref ref="WARN_FILE" /> |
||||
|
<appender-ref ref="ERROR_FILE" /> |
||||
|
</root> |
||||
|
|
||||
|
<!--生产环境:输出到文件--> |
||||
|
<!--<springProfile name="pro">--> |
||||
|
<!--<root level="info">--> |
||||
|
<!--<appender-ref ref="CONSOLE" />--> |
||||
|
<!--<appender-ref ref="DEBUG_FILE" />--> |
||||
|
<!--<appender-ref ref="INFO_FILE" />--> |
||||
|
<!--<appender-ref ref="ERROR_FILE" />--> |
||||
|
<!--<appender-ref ref="WARN_FILE" />--> |
||||
|
<!--</root>--> |
||||
|
<!--</springProfile>--> |
||||
|
|
||||
|
</configuration> |
||||
Loading…
Reference in new issue