Thursday, April 17, 2008

Log4JWebConfigurer Not Suited for J2EE

It's not uncommon to want to be able to change the logging configuration of a running application without restarting the application. There are a few mechanisms for doing this. One, which I've used in the past, is to expose Log4J via JMX. It's a bit of work, but not terrifically hard.

Another mechanism is to have the logging framework watch its own configuration file and, if it changes, reconfigure itself. Log4J has a mechanism for this, which Spring exposes through the Log4JConfigurator (Log4jWebConfigurator, etc.)

Unfortunately, it seems as if, at least according to the Spring folks, and their documentation, Log4J's mechanism doesn't do a good job of shutting down its thread, and therefore should not be used in a production setting.

That means that either I'm going to have to back to using the JMX approach or, alternately, switch the project to LogBack, which has a JMX Configurator built-in, and can reload from configuration using JMX.

2 comments:

Anonymous said...

Note: Log4JConfigurator's sole (nor main) purpose is not to setup auto-refreshing. Further, it's Log4J's auto-refreshing mechanism is the thing at issue, not something specific to Log4JConfigurator.

Log4JConfigurator is useful, probably not for the purposes mentioned here, but for dynamic selection of log files at runtime. (ie. not fully openly dynamic configuration, but selection of a pre-configured set).

Thus: Log4JConfigurator is "Not Suited for J2EE" only if Log4J is "Not Suited for J2EE".

Geoffrey Wiseman said...

Sure -- a more accurate title might be "Log4JConfigurer Auto-Refresh Not Suited for J2EE."

I think that's fairly clear in the text itself; it's not always easy to fit all the relevant details in a headline.