claya
claya

Reputation: 2020

How can I write to my java logback log the properties the tomcat server is running with on startup?

I'd like to see some of the property settings in my log of what the java server is initialized with. Not on each request just at startup. How can I set that up?

Upvotes: 1

Views: 44

Answers (1)

Andrew
Andrew

Reputation: 362

One way to do it might be to create a ServletContextListener that logs the properties in the contextInitialized method. For example:

public class LoggingServletContextListener
           implements ServletContextListener {

  private static final Logger logger = LogManager.getLogger(LoggingServletContextListener.class);

  @Override
  public void contextDestroyed(ServletContextEvent sce) {

  }

  @Override
  public void contextInitialized(ServletContextEvent arg0) {
    logger.info(System.getProperties());      
  }
}

You would need to include the listener in your web.xml file. You can read more about ServletContextListener here:

Upvotes: 2

Related Questions