我正在部署应用程序ear,它的lib文件夹中有log4j jar。我将log4j.properties放在文件夹/ opt / beavas / vn_home中,我使用环境变量读取。
我按如下方式初始化log4j
Properties log4jProperties = new Properties();
inputStream = new FileInputStream("path to log4j.properties");
log4jProperties.load(inputStream);
PropertyConfigurator.configure(log4jProperties);
然后我用
Logger.getLogger(clazz).log(LoggerUtilities.class.getName(), level, msg, t);
其中clazz是我从我的应用程序发送的类名,LoggerUtilities是初始化logger的常用类。
level- log level, msg- log meesage, t- Throwable object is any.
我的log4j.properties文件如下
log4j.appender.vaservices=org.apache.log4j.RollingFileAppender
log4j.appender.vaservices.file=/opt/beavas/logs/vas_new.log
log4j.appender.vaservices.MaxFileSize=100MB
log4j.appender.vaservices.MaxBackupIndex=100
log4j.appender.vaservices.append=true
log4j.appender.vaservices.layout=org.apache.log4j.PatternLayout
log4j.appender.vaservices.layout.ConversionPattern=%d{ISO8601}|%-5p|%L|%t|%c|%-6m %n
log4j.logger.com.tieto.vn.vas = DEBUG, vaservices
log4j.logger.com.tieto.tix.core = DEBUG, vaservices
log4j.logger.com.tieto.tix.imaging = DEBUG, vaservices
文件vas_new.log在应用程序更新时获取创建但不写入日志。如何解决?
答案 0 :(得分:1)
在log4j.properties中添加一行,如下所示:
log4j.rootLogger = DEBUG, vaservices