我有一个使用 Netbeans 和 glassfish 3.1.2 的 EJB 模块。我需要实现日志,但我不知道如何在 EJB 中配置 log4j。我在部署时遇到了这个问题:
SEVERE: log4j:ERROR Ignoring configuration file [file:/C:/Users/Luis Carlos/AppData/Roaming/NetBeans/7.2/config/GF3/domain1/config/log4j.properties].
SEVERE: log4j:WARN No appenders could be found for logger (beans.RutasBean).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
它显示在 glassfish 服务器控制台中。
这是 log4j.properties 文件:
log4j.rootLogger=DEBUG, FILE
log4j.logger.myapp=DEBUG
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=/space/gfv3/v3setup/GlassFish3/GlassFish/domains/domain1/logs/log4j.log
log4j.appender.FILE.MaxFileSize=100KB
log4j.appender.FILE.MaxBackupIndex=1
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{DATE} %-5p %c{1} : %m%n
我试过
了
,它说我必须在 glassfish 的服务器管理员中配置这样的属性文件,
-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/config/log4j.properties
但没有用
我有一个 Singleton Session Bean,在启动方法中我配置了日志,所以据此我在 bean 中有:
private Logger log;
private static final String LOG4J_PROPERTIES = "/log4j.properties";
@PostConstruct
public void startup(){
URL url = this.getClass().getResource(LOG4J_PROPERTIES);
if(url == null || url.getFile().length() == 0) {
throw new RuntimeException("Log4j config file "+ LOG4J_PROPERTIES +" not found");
}
PropertyConfigurator.configure(url);
log = Logger.getLogger(this.getClass());
log.info("Starting application");
em = Persistence.createEntityManagerFactory("BuscaBus-ejbPU");
rutaController = new RutaJpaController(ut, em);
actualizarCoordenadasRutas();
...
}
但仍然出现同样的错误
如何在 EJB 环境中配置 log4j?谢谢