You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
9.2 KiB

2 years ago
<?xml version="1.0" encoding="UTF-8"?>
<!--配置说明:
https://www.cnblogs.com/jybky/p/12204586.html
https://blog.csdn.net/wzygis/article/details/103189490
https://www.cnblogs.com/xrq730/p/8628945.html
https://www.jianshu.com/p/af5a7bab0e59
https://blog.csdn.net/wzygis/article/details/103189490
https://juejin.cn/post/6844903775631572999
-->
<configuration scan="true" scanPeriod="30 seconds" debug="false">
<contextName>nlAdmin</contextName>
<property name="log.charset" value="utf-8"/>
<property name="log.pattern"
value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
<springProperty scope="context" name="lokiUrl" source="loki.url"/>
<springProperty scope="context" name="systemName" source="loki.systemName"/>
<property name="LOKI_URL" value="${lokiUrl}"/>
<property name="SYSTEM_NAME" value="${systemName}"/>
<property name="LOG_HOME" value="${logPath}"/>
<!--引入默认的一些设置-->
<!--<include resource="log/XrToMes.xml"/>
<include resource="log/MesToErp.xml"/>-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
<charset>${log.charset}</charset>
</encoder>
</appender>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${logPath}"/>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
<!--单个日志最大容量 至少10MB才能看得出来-->
<maxFileSize>200MB</maxFileSize>
<!--所有日志最多占多大容量-->
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!--异步到文件-->
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>500</queueSize>
<appender-ref ref="FILE"/>
</appender>
<!--添加loki-->
<appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<batchTimeoutMs>1000</batchTimeoutMs>
<http class="com.github.loki4j.logback.ApacheHttpSender">
<url>${LOKI_URL}/push</url>
</http>
<format>
<label>
<pattern>system=${SYSTEM_NAME},level=%level,logType=%X{log_file_type:-logType}</pattern>
</label>
<message>
<pattern>${log.pattern}</pattern>
</message>
<sortByTime>true</sortByTime>
</format>
</appender>
<!--开发环境:打印控制台-->
<springProfile name="dev">
<root level="debug">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="lokiAppender" />
</root>
<logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.github.loki4j.client.pipeline" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
2 years ago
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.hibernate" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="io.netty" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="io.lettuce" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.fasterxml" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.quartz" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.google" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="springfox" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="log4jdbc" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="nl.basjes" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
</springProfile>
<!--生产环境:打印控制台和输出到文件-->
<springProfile name="prod">
<root level="info">
<!-- <appender-ref ref="asyncFileAppender"/>-->
2 years ago
<appender-ref ref="lokiAppender"/>
<!-- <appender-ref ref="CONSOLE"/>-->
</root>
<logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.hibernate" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="io.netty" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="jdbc" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="io.lettuce" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="com.fasterxml" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.quartz" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="com.google" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="springfox" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="log4jdbc" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="nl.basjes" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.jinterop" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.openscada" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.nl.modules.wql" level="info" additivity="false">
2 years ago
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
</springProfile>
<!--测试环境:打印控制台-->
<springProfile name="test">
<root level="info">
<appender-ref ref="asyncFileAppender"/>
</root>
<logger name="jdbc.audit" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc.resultset" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="springfox.documentation" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc.resultsettable" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc.sqlonly" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
</springProfile>
</configuration>