描述:正常情况下:在Springboot 项目的resources目录下创建一个logback-spring.xml的日志配置文件,简单配置如下:
- "1.0" encoding="UTF-8"?>
-
"false"> "LOG_HOME" value="./logs" /> "STDOUT" class="ch.qos.logback.core.ConsoleAppender"> -
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"> -
-
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n -
"FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> -
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> -
-
${LOG_HOME}/info.log.%d{yyyy-MM-dd}.log -
-
30 -
-
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"> -
-
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n -
-
-
"ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> -
10MB -
-
-
"INFO"> -
"STDOUT" /> -
"FILE" /> -
项目启动后日志都会存储在:部署目录下的 logs 文件夹下面:
文件名称为:
如图:
存在的问题:当Springboot项目集群多节点部署时候,多个项目指向的是同一个logback日志文件,如何区分开?
解决:增加端口号区分即可
新增获取端口配置:
并且在文件名称处,获取端口号即可:
- "1.0" encoding="UTF-8"?>
-
"false"> "LOG_HOME" value="./wzzs-log" /> "port" scope="context" source="server.port" defaultValue="0000"/> "STDOUT" class="ch.qos.logback.core.ConsoleAppender"> -
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"> -
-
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n -
"FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> -
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> -
-
${LOG_HOME}/TestWeb.log.%d{yyyy-MM-dd}.${port}.log -
-
30 -
-
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"> -
-
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n -
-
-
"ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> -
10MB -
-
-
"INFO"> -
"STDOUT" /> -
"FILE" /> -
最终结果:根据每个项目端口号区分开