我有一个在应用程序服务器(Weblogic)上实例化了3次的应用程序。问题是我无法分别获得三个不同的.log文件。我应该使用哪种log4j配置?
我尝试使用此log4j.properties:
log4j.rootCategory=DEBUG
#Loggers
log4j.logger.incmonit=INFO, incmonitLogger, servicesLogger, comandosLogger
##### Configuramos los appenders
# Appender stdout (salida estándar)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p [%c{2}] %m%n
log4j.appender.stdout.Threshold=ERROR
# ------------------------------ Incmonit ------------------------------- #
log4j.appender.incmonitLogger=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.incmonitLogger.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.incmonitLogger.rollingPolicy.maxIndex=4
log4j.appender.incmonitLogger.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.incmonitLogger.TriggeringPolicy.maxFileSize=250000000
log4j.appender.incmonitLogger.rollingPolicy.FileNamePattern=C:/tmp/MsgListener${hostName}-%i.log
log4j.appender.incmonitLogger.rollingPolicy.ActiveFileName=C:/tmp/MsgListener_${hostName}.log
log4j.appender.incmonitLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.incmonitLogger.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p [%c{2}] %m%n
log4j.appender.incmonitLogger.Append=true
log4j.appender.incmonitLogger.ImmediateFlush=true
log4j.category.incmonit=INFO, incmonitLogger
# Necesario para que no adicione al mismo archivo el log.
log4j.additivty.incmonitLogger=false
# ------------------------------ Services ------------------------------- #
log4j.appender.servicesLogger=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.servicesLogger.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.servicesLogger.rollingPolicy.maxIndex=4
log4j.appender.servicesLogger.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.servicesLogger.TriggeringPolicy.maxFileSize=250000000
log4j.appender.servicesLogger.rollingPolicy.FileNamePattern=C:/tmp/MsgListenerServices_${hostName}-%i.log
log4j.appender.servicesLogger.rollingPolicy.ActiveFileName=C:/tmp/MsgListenerServices_${hostName}.log
log4j.appender.servicesLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.servicesLogger.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p [%c{2}] %m%n
log4j.appender.servicesLogger.Append=true
log4j.appender.servicesLogger.ImmediateFlush=true
log4j.category.services=INFO, servicesLogger
# Necesario para que no adicione al mismo archivo el log.
log4j.additivty.servicesLogger=false
# ------------------------------ Comandos ------------------------------- #
log4j.appender.comandosLogger=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.comandosLogger.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.comandosLogger.rollingPolicy.maxIndex=4
log4j.appender.comandosLogger.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.comandosLogger.TriggeringPolicy.maxFileSize=250000000
log4j.appender.comandosLogger.rollingPolicy.FileNamePattern=C:/tmp/MsgListenerComandos_${hostName}-%i.log
log4j.appender.comandosLogger.rollingPolicy.ActiveFileName=C:/tmp/MsgListenerComandos_${hostName}.log
log4j.appender.comandosLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.comandosLogger.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p [%c{2}] %m%n
log4j.appender.comandosLogger.Append=true
log4j.appender.comandosLogger.ImmediateFlush=true
log4j.category.comandos=INFO, comandosLogger
# Necesario para que no adicione al mismo archivo el log.
log4j.additivty.comandosLogger=false
但是,由于它们共享同一个包,因此它同时写入了三个文件中。