1

I am running Spring through tomcat and using Log4j. I have recently added a spring bean to handle a graceful shutdown of the Spring Integration components.

This all works fine but my logging output in my destroy method is lost - I assume this is because log4j has already been terminated. I can see output by using System.out.

My bean's destroy method is called from the spring config "destroy-method" The logging inside the bean is via:

private final static Logger LOGGER = Logger.getLogger(Monitor.class.getName()); 
...
LOGGER.info("Application shutdown started");

I have log4j on the classpath (which is the only way Spring is aware of it) and a log4j.properties file.

I am thinking because my bean does not directly rely on log4j, Spring is terminating it before my destroy() method.

Does anybody know of some way to make Spring hold onto log4j until I have finished my destroy()?

mnik
  • 137
  • 1
  • 9
  • What's your log4j config? Is the logger for Monitor.class correctly configured? – Pino Jun 06 '14 at 15:03
  • The config works since the Monitor class also has an init() method which outputs correctly: public void init() { LOGGER.info("Application started"); } – mnik Jun 06 '14 at 15:49
  • Why do you think that your destroy method is called? See for example http://stackoverflow.com/questions/16783552/destroy-method-is-not-working-in-spring-framework – Pino Jun 09 '14 at 06:40
  • The destroy() is definitley called since I see output from it using System.out – mnik Jun 12 '14 at 17:19

0 Answers0