haungxing
11 months ago
13 changed files with 504 additions and 424 deletions
@ -0,0 +1,320 @@
|
||||
package com.hnac.hzims.operational.util; |
||||
|
||||
import com.documents4j.api.DocumentType; |
||||
import com.documents4j.api.IConverter; |
||||
import com.documents4j.job.LocalConverter; |
||||
import com.hnac.hzims.operational.annotation.DefaultValue; |
||||
import com.hnac.hzims.ticket.constants.TicketConstants; |
||||
import com.spire.xls.FileFormat; |
||||
import com.spire.xls.Workbook; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.io.IOUtils; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.*; |
||||
import java.lang.reflect.Field; |
||||
import java.net.URLEncoder; |
||||
import java.nio.file.Files; |
||||
import java.time.LocalDateTime; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @author hx |
||||
*/ |
||||
@Slf4j |
||||
public class PdfUtils { |
||||
|
||||
/** 文件后缀名 **/ |
||||
public static String DOC_SUFFIX = ".doc"; |
||||
public static String DOCX_SUFFIX = ".docx"; |
||||
public static String XLS_SUFFIX = ".xls"; |
||||
public static String XLSX_SUFFIX = ".xlsx"; |
||||
public static String PDF_SUFFIX = ".pdf"; |
||||
|
||||
/*** |
||||
* 各文件转换为pdf |
||||
* @param templatePath 待转换的文件路径 |
||||
* @param templateFileName 待转换的文件名 |
||||
* @param savePath 转换为pdf后的文件路径 |
||||
* @param saveFileName 转换为pdf后的文件名称 |
||||
* @return |
||||
*/ |
||||
public static void convertPdf(String templatePath, String templateFileName, String savePath, String saveFileName) { |
||||
String templateFilePath = templatePath + templateFileName; |
||||
String saveFilePath = savePath + saveFileName; |
||||
log.info("转换前的文件为:{};转换后的路径为:{}", templateFilePath, saveFilePath); |
||||
File templateFile = new File(templateFilePath); |
||||
File saveFile = new File(saveFilePath); |
||||
//获取文件类型
|
||||
String fileType = templateFileName.substring(templateFileName.lastIndexOf(".")); |
||||
InputStream inputStream = null; |
||||
OutputStream outputStream = null; |
||||
try { |
||||
try { |
||||
inputStream = Files.newInputStream(templateFile.toPath()); |
||||
outputStream = Files.newOutputStream(saveFile.toPath()); |
||||
//document4j 转换 pdf linux环境下不支持
|
||||
if (DOCX_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (DOC_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (XLS_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (XLSX_SUFFIX.equals(fileType)) { |
||||
//此方式行不通
|
||||
//converter.convert(inputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute();
|
||||
Workbook wb = new Workbook(); |
||||
wb.loadFromFile(templateFilePath); |
||||
wb.saveToFile(saveFilePath, FileFormat.PDF); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("转换失败,错误信息为:{}", e.getMessage()); |
||||
throw new ServiceException(e.getMessage()); |
||||
} finally { |
||||
inputStream.close(); |
||||
outputStream.close(); |
||||
} |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 对象转化为Map 并设置默认值 |
||||
* |
||||
* @param obj |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Map<String, Object> objectToMap(Object obj) { |
||||
Map<String, Object> result = new HashMap<>(); |
||||
if (ObjectUtil.isNotEmpty(obj)) { |
||||
Class clazz = obj.getClass(); |
||||
List<Field> fieldList = new ArrayList<>(); |
||||
while (clazz != null) { |
||||
fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); |
||||
clazz = clazz.getSuperclass(); |
||||
} |
||||
fieldList.forEach(field -> { |
||||
field.setAccessible(true); |
||||
DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); |
||||
Object value; |
||||
try { |
||||
value = field.get(obj); |
||||
} catch (IllegalAccessException e) { |
||||
throw new ServiceException("获取属性性出错"); |
||||
} |
||||
//若为list则不处理
|
||||
if (value instanceof List) { |
||||
return; |
||||
} |
||||
//若为时间格式则进行格式化
|
||||
if (value instanceof LocalDateTime) { |
||||
value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
if (value instanceof Date) { |
||||
value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
|
||||
//如果value为空直接跳出
|
||||
// if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){
|
||||
// return;
|
||||
// }
|
||||
|
||||
//属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值
|
||||
if (ObjectUtil.isNotEmpty(defaultValue)) { |
||||
result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), |
||||
ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); |
||||
} else { |
||||
result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); |
||||
|
||||
} |
||||
}); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 对象转化为Map 并设置默认值 |
||||
* |
||||
* @param obj |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Map<String, Object> objectToMap(Object obj, boolean isWordFlag) { |
||||
Map<String, Object> result = new HashMap<>(); |
||||
if (ObjectUtil.isNotEmpty(obj)) { |
||||
Class clazz = obj.getClass(); |
||||
List<Field> fieldList = new ArrayList<>(); |
||||
while (clazz != null) { |
||||
fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); |
||||
clazz = clazz.getSuperclass(); |
||||
} |
||||
fieldList.forEach(field -> { |
||||
field.setAccessible(true); |
||||
DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); |
||||
Object value; |
||||
try { |
||||
value = field.get(obj); |
||||
} catch (IllegalAccessException e) { |
||||
throw new ServiceException("获取属性性出错"); |
||||
} |
||||
//若为list则不处理
|
||||
if (value instanceof List) { |
||||
return; |
||||
} |
||||
//若为时间格式则进行格式化
|
||||
if (value instanceof LocalDateTime) { |
||||
value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
if (value instanceof Date) { |
||||
value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
|
||||
//如果value为空直接跳出
|
||||
// if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){
|
||||
// return;
|
||||
// }
|
||||
|
||||
//属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值
|
||||
if (ObjectUtil.isNotEmpty(defaultValue)) { |
||||
result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), |
||||
ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); |
||||
} else { |
||||
if (isWordFlag) { |
||||
//如果导出word为null会出现{{ ,value设置"\u00A0"
|
||||
result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0")); |
||||
} else { |
||||
result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 对象转化为Map 并设置默认值 |
||||
* |
||||
* @param obj |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Map<String, Object> objectToMapResult(Object obj, Map<String, Object> map) { |
||||
Map<String, Object> result = new HashMap<>(); |
||||
if (ObjectUtil.isNotEmpty(obj)) { |
||||
Class clazz = obj.getClass(); |
||||
List<Field> fieldList = new ArrayList<>(); |
||||
while (clazz != null) { |
||||
fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); |
||||
clazz = clazz.getSuperclass(); |
||||
} |
||||
fieldList.forEach(field -> { |
||||
field.setAccessible(true); |
||||
DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); |
||||
Object value; |
||||
try { |
||||
value = field.get(obj); |
||||
} catch (IllegalAccessException e) { |
||||
throw new ServiceException("获取属性性出错"); |
||||
} |
||||
//若为list则不处理
|
||||
if (value instanceof List) { |
||||
return; |
||||
} |
||||
//若为时间格式则进行格式化
|
||||
if (value instanceof LocalDateTime) { |
||||
value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
if (value instanceof Date) { |
||||
value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); |
||||
} |
||||
|
||||
if (map.containsKey(field.getName())) { |
||||
return; |
||||
} |
||||
|
||||
//属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值
|
||||
if (ObjectUtil.isNotEmpty(defaultValue)) { |
||||
result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), |
||||
ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); |
||||
} else { |
||||
//如果导出word为null会出现{{ ,value设置"\u00A0"
|
||||
result.put(field.getName(), Optional.ofNullable(value).orElse("")); |
||||
} |
||||
}); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 读取本地pdf,这里设置的是预览 |
||||
*/ |
||||
public static void readPdf(HttpServletResponse response, String filePath) { |
||||
response.reset(); |
||||
response.setContentType("application/pdf"); |
||||
FileInputStream fileInputStream = null; |
||||
OutputStream outputStream = null; |
||||
try { |
||||
File file = new File(filePath); |
||||
fileInputStream = new FileInputStream(file); |
||||
outputStream = response.getOutputStream(); |
||||
IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); |
||||
response.setHeader("Content-Disposition", |
||||
"inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); |
||||
outputStream.flush(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
try { |
||||
fileInputStream.close(); |
||||
outputStream.close(); |
||||
|
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 读取本地pdf,这里设置的是导出 |
||||
*/ |
||||
public static void exportPdf(HttpServletResponse response, String filePath) { |
||||
response.reset(); |
||||
response.setContentType("application/pdf"); |
||||
FileInputStream fileInputStream = null; |
||||
OutputStream outputStream = null; |
||||
try { |
||||
File file = new File(filePath); |
||||
fileInputStream = new FileInputStream(file); |
||||
outputStream = response.getOutputStream(); |
||||
IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); |
||||
response.setHeader("Content-Disposition", "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); |
||||
outputStream.flush(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
try { |
||||
fileInputStream.close(); |
||||
outputStream.close(); |
||||
|
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration scan="true" scanPeriod="60 seconds"> |
||||
<!-- 自定义参数监听 --> |
||||
<contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/> |
||||
|
||||
<!-- 彩色日志依赖的渲染类 --> |
||||
<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="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern> |
||||
<charset>utf8</charset> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
||||
<property name="log.pattern" |
||||
value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%t] [%X{traceId}] %-5level %logger{50} - %msg%n"/> |
||||
|
||||
<!-- 生成日志文件 --> |
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/info.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!-- 日志文件输出的文件名 --> |
||||
<fileNamePattern>log/info/info-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!--设置保存10天 一天24个文件,一小时生成一个--> |
||||
<MaxHistory>240</MaxHistory> |
||||
<!--给定日志文件大小,超过指定的大小就新建一个日志文件--> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!-- 总日志大小 --> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!-- 打印日志级别 --> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>INFO</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<!-- 生成日志文件 --> |
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/error.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!-- 日志文件输出的文件名 --> |
||||
<fileNamePattern>log/error/error-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!--设置保存15天 一天24个文件,一小时生成一个--> |
||||
<MaxHistory>360</MaxHistory> |
||||
<!--给定日志文件大小,超过指定的大小就新建一个日志文件--> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!-- 总日志大小 --> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!-- 打印日志级别 --> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>ERROR</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<!-- 日志输出级别 --> |
||||
<root level="ERROR"> |
||||
<appender-ref ref="STDOUT"/> |
||||
<!--<appender-ref ref="INFO"/>--> |
||||
<appender-ref ref="ERROR"/> |
||||
</root> |
||||
|
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
|
||||
|
||||
<!-- MyBatis log configure --> |
||||
<logger name="com.apache.ibatis" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="java.sql.Connection" level="ERROR"/> |
||||
<logger name="java.sql.Statement" level="ERROR"/> |
||||
<logger name="java.sql.PreparedStatement" level="ERROR"/> |
||||
|
||||
<!-- 减少部分debug日志 --> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
<logger name="org.apache.shiro" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="org.springframework" level="ERROR"/> |
||||
<logger name="org.springframework.context" level="ERROR"/> |
||||
<logger name="org.springframework.beans" level="ERROR"/> |
||||
<logger name="com.baomidou.mybatisplus" level="ERROR"/> |
||||
<logger name="org.apache.ibatis.io" level="ERROR"/> |
||||
<logger name="org.apache.velocity" level="ERROR"/> |
||||
<logger name="org.eclipse.jetty" level="ERROR"/> |
||||
<logger name="io.undertow" level="ERROR"/> |
||||
<logger name="org.xnio.nio" level="ERROR"/> |
||||
<logger name="org.thymeleaf" level="ERROR"/> |
||||
<logger name="springfox.documentation" level="ERROR"/> |
||||
<logger name="org.hibernate.validator" level="ERROR"/> |
||||
<logger name="com.netflix.loadbalancer" level="ERROR"/> |
||||
<logger name="com.netflix.hystrix" level="ERROR"/> |
||||
<logger name="com.netflix.zuul" level="ERROR"/> |
||||
<logger name="de.codecentric" level="ERROR"/> |
||||
<!-- cache ERROR --> |
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="org.springframework.cache" level="ERROR"/> |
||||
<!-- cloud --> |
||||
<logger name="org.apache.http" level="ERROR"/> |
||||
<logger name="com.netflix.discovery" level="ERROR"/> |
||||
<logger name="com.netflix.eureka" level="ERROR"/> |
||||
<!-- 业务日志 --> |
||||
<Logger name="org.springblade" level="ERROR"/> |
||||
<Logger name="org.springblade.core.version" level="ERROR"/> |
||||
|
||||
<!-- 减少nacos日志 --> |
||||
<logger name="com.alibaba.nacos" level="ERROR"/> |
||||
|
||||
</configuration> |
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration scan="true" scanPeriod="60 seconds"> |
||||
<!-- 自定义参数监听 --> |
||||
<contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/> |
||||
|
||||
<!-- 彩色日志依赖的渲染类 --> |
||||
<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="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern> |
||||
<charset>utf8</charset> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
||||
<property name="log.pattern" |
||||
value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%t] [%X{traceId}] %-5level %logger{50} - %msg%n"/> |
||||
|
||||
<!-- 生成日志文件 --> |
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/info.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!-- 日志文件输出的文件名 --> |
||||
<fileNamePattern>log/info/info-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!--设置保存10天 一天24个文件,一小时生成一个--> |
||||
<MaxHistory>240</MaxHistory> |
||||
<!--给定日志文件大小,超过指定的大小就新建一个日志文件--> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!-- 总日志大小 --> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!-- 打印日志级别 --> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>INFO</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<!-- 生成日志文件 --> |
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/error.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!-- 日志文件输出的文件名 --> |
||||
<fileNamePattern>log/error/error-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!--设置保存15天 一天24个文件,一小时生成一个--> |
||||
<MaxHistory>360</MaxHistory> |
||||
<!--给定日志文件大小,超过指定的大小就新建一个日志文件--> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!-- 总日志大小 --> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!-- 打印日志级别 --> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>ERROR</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<!-- 日志输出级别 --> |
||||
<root level="ERROR"> |
||||
<appender-ref ref="STDOUT"/> |
||||
<!--<appender-ref ref="INFO"/>--> |
||||
<appender-ref ref="ERROR"/> |
||||
</root> |
||||
|
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
|
||||
|
||||
<!-- MyBatis log configure --> |
||||
<logger name="com.apache.ibatis" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="java.sql.Connection" level="ERROR"/> |
||||
<logger name="java.sql.Statement" level="ERROR"/> |
||||
<logger name="java.sql.PreparedStatement" level="ERROR"/> |
||||
|
||||
<!-- 减少部分debug日志 --> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
<logger name="org.apache.shiro" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="org.springframework" level="ERROR"/> |
||||
<logger name="org.springframework.context" level="ERROR"/> |
||||
<logger name="org.springframework.beans" level="ERROR"/> |
||||
<logger name="com.baomidou.mybatisplus" level="ERROR"/> |
||||
<logger name="org.apache.ibatis.io" level="ERROR"/> |
||||
<logger name="org.apache.velocity" level="ERROR"/> |
||||
<logger name="org.eclipse.jetty" level="ERROR"/> |
||||
<logger name="io.undertow" level="ERROR"/> |
||||
<logger name="org.xnio.nio" level="ERROR"/> |
||||
<logger name="org.thymeleaf" level="ERROR"/> |
||||
<logger name="springfox.documentation" level="ERROR"/> |
||||
<logger name="org.hibernate.validator" level="ERROR"/> |
||||
<logger name="com.netflix.loadbalancer" level="ERROR"/> |
||||
<logger name="com.netflix.hystrix" level="ERROR"/> |
||||
<logger name="com.netflix.zuul" level="ERROR"/> |
||||
<logger name="de.codecentric" level="ERROR"/> |
||||
<!-- cache INFO --> |
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="org.springframework.cache" level="ERROR"/> |
||||
<!-- cloud --> |
||||
<logger name="org.apache.http" level="ERROR"/> |
||||
<logger name="com.netflix.discovery" level="ERROR"/> |
||||
<logger name="com.netflix.eureka" level="ERROR"/> |
||||
<!-- 业务日志 --> |
||||
<Logger name="org.springblade" level="ERROR"/> |
||||
<Logger name="org.springblade.core.version" level="ERROR"/> |
||||
|
||||
<!-- 减少nacos日志 --> |
||||
<logger name="com.alibaba.nacos" level="ERROR"/> |
||||
|
||||
</configuration> |
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration scan="true" scanPeriod="60 seconds"> |
||||
<!-- 自定义参数监听 --> |
||||
<contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/> |
||||
|
||||
<!-- 彩色日志依赖的渲染类 --> |
||||
<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="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern> |
||||
<charset>utf8</charset> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
||||
<property name="log.pattern" |
||||
value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%t] [%X{traceId}] %-5level %logger{50} - %msg%n"/> |
||||
|
||||
<!-- 生成日志文件 |
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/info.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!– 日志文件输出的文件名 –> |
||||
<fileNamePattern>log/info/info-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!–设置保存10天 一天24个文件,一小时生成一个–> |
||||
<MaxHistory>240</MaxHistory> |
||||
<!–给定日志文件大小,超过指定的大小就新建一个日志文件–> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!– 总日志大小 –> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!– 打印日志级别 –> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>INFO</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender>--> |
||||
|
||||
<!-- 生成日志文件 --> |
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>log/error.log</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
||||
<!-- 日志文件输出的文件名 --> |
||||
<fileNamePattern>log/error/error-%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern> |
||||
<!--设置保存15天 一天24个文件,一小时生成一个--> |
||||
<MaxHistory>360</MaxHistory> |
||||
<!--给定日志文件大小,超过指定的大小就新建一个日志文件--> |
||||
<maxFileSize>20MB</maxFileSize> |
||||
<totalSizeCap>10GB</totalSizeCap> <!-- 总日志大小 --> |
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart> |
||||
</rollingPolicy> |
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<!-- 打印日志级别 --> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>ERROR</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<!-- 日志输出级别 --> |
||||
<root level="ERROR"> |
||||
<appender-ref ref="STDOUT"/> |
||||
<!--<appender-ref ref="INFO"/>--> |
||||
<appender-ref ref="ERROR"/> |
||||
</root> |
||||
|
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
|
||||
|
||||
<!-- MyBatis log configure --> |
||||
<logger name="com.apache.ibatis" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="java.sql.Connection" level="ERROR"/> |
||||
<logger name="java.sql.Statement" level="ERROR"/> |
||||
<logger name="java.sql.PreparedStatement" level="ERROR"/> |
||||
|
||||
<!-- 减少部分debug日志 --> |
||||
<logger name="druid.sql" level="ERROR"/> |
||||
<logger name="org.apache.shiro" level="ERROR"/> |
||||
<logger name="org.mybatis.spring" level="ERROR"/> |
||||
<logger name="org.springframework" level="ERROR"/> |
||||
<logger name="org.springframework.context" level="ERROR"/> |
||||
<logger name="org.springframework.beans" level="ERROR"/> |
||||
<logger name="com.baomidou.mybatisplus" level="ERROR"/> |
||||
<logger name="org.apache.ibatis.io" level="ERROR"/> |
||||
<logger name="org.apache.velocity" level="ERROR"/> |
||||
<logger name="org.eclipse.jetty" level="ERROR"/> |
||||
<logger name="io.undertow" level="ERROR"/> |
||||
<logger name="org.xnio.nio" level="ERROR"/> |
||||
<logger name="org.thymeleaf" level="ERROR"/> |
||||
<logger name="springfox.documentation" level="ERROR"/> |
||||
<logger name="org.hibernate.validator" level="ERROR"/> |
||||
<logger name="com.netflix.loadbalancer" level="ERROR"/> |
||||
<logger name="com.netflix.hystrix" level="ERROR"/> |
||||
<logger name="com.netflix.zuul" level="ERROR"/> |
||||
<logger name="de.codecentric" level="ERROR"/> |
||||
<!-- cache INFO --> |
||||
<logger name="net.sf.ehcache" level="ERROR"/> |
||||
<logger name="org.springframework.cache" level="ERROR"/> |
||||
<!-- cloud --> |
||||
<logger name="org.apache.http" level="ERROR"/> |
||||
<logger name="com.netflix.discovery" level="ERROR"/> |
||||
<logger name="com.netflix.eureka" level="ERROR"/> |
||||
<!-- 业务日志 --> |
||||
<Logger name="org.springblade" level="ERROR"/> |
||||
<Logger name="org.springblade.core.version" level="ERROR"/> |
||||
|
||||
<!-- 减少nacos日志 --> |
||||
<logger name="com.alibaba.nacos" level="ERROR"/> |
||||
|
||||
</configuration> |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue