Articles

How to set Atomikos to not write to console logs?

In JEE on April 20, 2010 by petrem66

For a while, I’ve been using the distributed transaction manager from  Atomikos Transactions Essential for my XTransactions. It works neat except that it tends to be verbose when left on its own device (logging way). Today, I’ve taken a bit of a time to look into fixing that problem in order to trim down the irrelevant messages on the console in my web applications. And I’ve found a simple solution. Here it is

I’ve figured out a way to do that. It is actually very simple since Atomikos uses a centralize class to do the logging called com.atomikos.icatch.system.Configuration. Logging is actually performed with implementations of com.atomikos.diagnostics.Console so all I had to do is to un-register all default consoles and register my own implementation that’s based on commons logging. For that, I have implements a class called Log4JConsole implementing com.atomikos.diagnostics.Console, and placed the following code:

try {
  Configuration.removeConsoles();
  Configuration.addConsole (new Log4JConsole());
  logger.debug(“Set log4j based console for atomikos”);
}
catch(Exception e) {
  logger.error(“Failed to initialize Atomikos”, e);
}

in the servlet.init(). One would argue that I could have implemented a special javax.servlet.ServletContextListener for that initialization to happen at application start-up. That would mean more work since Atomikos configures itself at first use that happens usually after the components using it do so. In my case, Spring FW and Hibernate FW have to come up first. These happen when the Servlet initializes itself

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: