self4j 微服务日志配置-按微服务应用分别生成不同的日志文件
如题:
效果是:在/opt/myApps/logs/app1/app1.log
/opt/myApps/logs/app2/app2.log
每个应用独立存储日志;
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="APPLICATION_NAME" source="spring.application.name"/>
<springProperty scope="context" name="LOG_HOME" source="logging.path"
defaultValue="/opt/myApps/logs"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/${APPLICATION_NAME}/${APPLICATION_NAME}.log/</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/${APPLICATION_NAME}/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
其他补充:
springProperty
标签可以定义变量,读取springboot中的配置的值,在logback的配置文件中通过变量名来引用;
边系鞋带边思考人生.