当想让所有的配置文件都在一个地方维护时,logback的配置文件怎么引用外部的统一的config.properties的配置呢?
config.properties配置如下
directory.Log=D://logs//oshop//
logback配置如下
<property resource="config.properties"/> <property name="USER_HOME" value="${directory.Log}" />注意:此处的config.properties在classes目录下,spring默认会寻找classes目录下的文件,虽然logback.xml和config.properties不在同一级目录,此处配置依然有效。
这样就可以在任意路径处使用USER_HOME
<appender name="tokenWarn" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Encoding>UTF-8</Encoding> <File>${USER_HOME}token-warn.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <FileNamePattern>${USER_HOME}token-warn.%i.log.zip</FileNamePattern> <MinIndex>1</MinIndex> <MaxIndex>10</MaxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date{MM-dd HH:mm:ss.SSS} [%F:%L][%-15t] - %msg%n</Pattern> </layout> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>WARN</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender>