公司升级了框架。之前的日志配置文件需要修改 修改之后的日志文件如下
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="TRACE"/>
<!-- 项目名称 -->
<property name="PROJECT_NAME" value="PROJECT_NAME"/>
<!--定义日志文件的存储地址 -->
<property name="LOG_HOME" value="logs"/>
<!-- ERROR日志文件,记录错误日志 -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/${PROJECT_NAME}/error.log</file>
<!-- 过滤器,只打印ERROR级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/${PROJECT_NAME}/%d{yyyy-MM-dd}/error.%i.gz</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>3650</MaxHistory>
<!--日志文件最大的大小-->
<MaxFileSize>100MB</MaxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!-- 格式化输出: %d: 日期; %-5level: 级别从左显示5个字符宽度; %thread: 线程名; %logger: 类名; %M: 方法名; %line: 行号; %msg: 日志消息; %n: 换行符 -->
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] [%logger{50}] [%M] [%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- INFO日志文件,用于记录重要日志信息 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/${PROJECT_NAME}/info.log</file>
<!-- 过滤器,只打印INFO级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/${PROJECT_NAME}/%d{yyyy-MM-dd}/info.%i.gz</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>3650</MaxHistory>
<!--日志文件最大的大小-->
<MaxFileSize>100MB</MaxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!-- 格式化输出: %d: 日期; %-5level: 级别从左显示5个字符宽度; %thread: 线程名; %logger: 类名; %M: 方法名; %line: 行号; %msg: 日志消息; %n: 换行符 -->
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] [%logger{50}] [%M] [%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 输出error信息到文件-->
<logger name="error" additivity="true">
<appender-ref ref="ERROR_FILE"/>
</logger>
<!-- 输出info信息到文件-->
<logger name="info" additivity="true">
<appender-ref ref="INFO_FILE"/>
</logger>
<!-- 生产环境下的日志配置 -->
<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ERROR_FILE"/>
<appender-ref ref="INFO_FILE"/>
</root>
</springProfile>
<!-- 开发、测试环境 -->
<springProfile name="dev,test">
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="INFO"/>
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="com.culturerbac" level="DEBUG"/>
</springProfile>
</configuration>
下面是启动脚本
export JAVA_HOME=/home/app/jdk1.8.0_161
export PATH=$PATH:/home/app/jdk1.8.0_161/bin
count=`ps -ef |grep culturerbac |grep -v "grep" |wc -l`
echo $count
if [ $count -eq 0 ]; then
nohup java -jar /opt/deploy/culturerbac-3.0.0.jar > /opt/deploy/logs/culture-rbac/culture-rbac.log 2>&1 &
tail -f /opt/deploy/logs/culture-rbac/culture-rbac.log
else
kill -9 `ps -ef|grep culturerbac|grep -v grep|awk '{print $2}'`
nohup java -jar /opt/deploy/culturerbac-3.0.0.jar > /opt/deploy/logs/culture-rbac/culture-rbac.log 2>&1 &
tail -f /opt/deploy/logs/culture-rbac/culture-rbac.log
fi
仅供参考。