我想用 log4j2 配置文件实现 spring 5,比如 dev、qa 和 prod。
目前,这就是我使用 log4j2 运行 spring 5 的方式,我在命令行中加载 log4j2 属性:
mvn tomcat8:run -Dlog4j.configurationFile=file:%path_to_log4j2_prop%/log4j2.properties
这是我的 log4j2 属性:
status = debug
name = PropertiesConfig
#Make sure to change log file path as per your need
property.environment=D:/WhiteCoats-New-Workspace/spring-5
property.servicesfilename = ${environment}/wc.out
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
appenders = services
appender.services.type = RollingFile
appender.services.name = ServiceFile
appender.services.fileName = ${servicesfilename}
appender.services.filePattern = ${environment}/wc.out-%d{yyyy-MM-dd}-%i
appender.services.layout.type = PatternLayout
appender.services.layout.pattern = [ %d{yyyy-MMM-dd HH:mm:ss a} ] - [%t] %-5level %logger{36} - %msg%n
appender.services.policies.type = Policies
appender.services.policies.time.type = TimeBasedTriggeringPolicy
appender.services.policies.time.interval = 1
appender.services.policies.time.modulate = true
appender.services.policies.size.type = SizeBasedTriggeringPolicy
appender.services.policies.size.size=5MB
appender.services.strategy.type = DefaultRolloverStrategy
appender.services.strategy.max = 10
loggers = services
#services logs
logger.services.name = com.vm
logger.services.level = debug
logger.services.additivity = false
logger.services.appenderRef.services.ref = ServiceFile
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = ServiceFile
在 spring 3 中,我使用了 log4j 并在 web.xml 中配置了路径。
我如何为 spring 5 实现 log4j2 的配置文件?