I am learning Hibernate with Spring and am creating an application using the same with JSF 2.0. I am trying to configure the logging in my application but the log statements in my code do not seem to get sent to the output (console in my case).
I can see the Hibernate logging statements though 😐
Following is my project structure :
And my log4j.properties :
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout
log4j.logger.org.hibernate=info
log4j.logger.org.springframework=warn
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=info
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=info
And here’s the code for the context listener class:
import org.apache.log4j.Logger;
...
...
...
public class HibernateListener implements ServletContextListener
{
private static final String CFG_PATH = "/WEB-INF/hibernate.cfg.xml";
private static final Logger LOGGER = Logger.getLogger(HibernateListener.class);
@Override
public void contextDestroyed(ServletContextEvent event) {
HibernateUtil.getSessionFactory().close();
}
@Override
public void contextInitialized(ServletContextEvent event) {
URL configFile = null;
try {
configFile = event.getServletContext().getResource(CFG_PATH);
HibernateUtil.buildSessionFactory(configFile);
LOGGER.info("Context initialization successful");
System.out.println("Context initialization successful");
}
catch (MalformedURLException e) {
System.err.println("Could not load hibernate configuration file - " + configFile);
}
}
}
I can’t see the INFO statement nor the sysout…

It seems there WAS an issue with app server starting due to which the code never reached the LOG statement. Problem resolved after creating fresh instance of the application server…