我正在按照本手册在Java应用程序中配置log4j2, https://logging.apache.org/log4j/2.x/manual/configuration.html
但是由于我有两个xml文件,我在提供文件路径时遇到了问题-
SERVICE_NAME="mailServer"
SERVICE_HOME=${SERVICE_HOME:="/srv/osgi"}
SERVICE_CONF=${SERVICE_CONF:="${SERVICE_HOME}"}
SERVICE_LOG4J_FILE=${SERVICE_LOG4J_FILE:="${SERVICE_CONF}/${SERVICE_NAME}-log4j.xml"}
SERVICE_LOG4J_OPTS=${SERVICE_LOG4J_OPTS:="-Dlog4j.configurationFile=file:${SERVICE_LOG4J_FILE}"}
现在我也想提供log4j2.xml的位置。
所以用逗号分隔文件名如下是否正确-
SERVICE_LOG4J_FILE=${SERVICE_LOG4J_FILE:="${SERVICE_CONF}/${SERVICE_NAME}-log4j.xml", "${SERVICE_CONF}/log4j2.xml"}
答案 0 :(得分:0)
# Root logger option
log4j.rootLogger=INFO, DEBUG, file,console
# Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Append=true
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss,SSS} %-5p [ %M ] ( %C ) %c{1}:%L - %m%n
# File Appender
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss,SSS} %-5p [ %M ] ( %C ) %c{1}:%L - %m%n
log4j.appender.file.File=C:/log/SpringMain.log
log4j.appender.file.MaxBackupIndex=10