Logging in Jboss sucks

This is a venting post.

I have a need to do the following. My app uses the Log4J API deployed on JBoss 6.1.x

A) Correlate log statements with a given thread of execution, logically identified by an arbitrary generated “request id” that my application sets at the entry point for a request, doing this using ThreadLocals. No, this is not a discussion for NDC/MDC.

B) These log statements will end up wherever the log system is configured to send them. I expect to be able to use that logging system’s documented APIs/configuration to add additional targets for log entries (appenders in log4j lingo)

C) Due to (A) and the sheer volume, I have the need to create a highly customized appender for log events that has access to my application’s context/services. The intent is to log these off asynchronously to a queue or a NoSql DB leveraging connections that my application already has handles on and configured itself. Hence I am not going to be able to reply on an instance of something that is instantiated and is outside of my application’s context. (i.e. I don’t want to configure this appender via the container’s default configuration mechanism, xml or whatever it is). I need to do this at runtime. My appender will need access to queues, and configuration, sources of connectivity that my application provides (not the deployment environment)

D) The logical approach would be to just use Log4J’s API and do something like:

Logger.getLogger("my.package.root").addAppender(new MySuperCustomizedAppender(configFromMyApp));

The above runs great in a unit test locally, I’m ready to go, lets deploy to JBoss!……oops wait, once deployed there nothing is happening.. whats going on??

E) When I do a Logger.getLogger() I get a nice instance of org.jboss.logmanager.log4j.BridgeLogger , looking at the source I see this little gem:

public void addAppender(final Appender newAppender) {
   // ignored
}

No warning. No Exception. No Message. Just silently discarded, letting you go ahead and waste your time trying to figure out what the hell is going on.

F) “Ok, someone else has certainly encountered this, lets google it”…. yep, doing a search on “BridgeLogger jboss addAppender” will yield you a whole lot of results and no definitive solution that really seems to do the job. Several forum posts going on and on with the lack of a satisfactory answer; several JIRA tickets documenting this issue etc. Overall the “workarounds” seem like way more trouble then they are worth (fiddling w/ jars, build/deploy routines, configurations etc on all app servers etc)

G) “Hmm, maybe I shouldn’t be using Log4J, how about Slf4J?”….. ok well, Slf4J provides a nice facade to logging. I’ll have to refactor a lot of my logging statements to use this API but it might be manageable. Then I can specifically target Log4j and bypass Jboss’s logging system…… oops. wait. no. JBoss also includes an SLF4J adapter of its own in the parent server level classpath, so if I create my own, since SLF4j does not permit multiple bindings, it will be a crap shoot for which one it picks…. Jboss’ or the one you want it to. Again the “solutions” for getting SLF4J to use your binding of choice over the one provided by JBoss seem like more “forum threads” with the lack of clear documented solution that does not involve your system administrators having to make farm wide config changes… @see F above. Forget it

H) Now what? Create my own “extension” of SLF4J or my own cloned interface of SLF4J that gives me some sort of hook that permits me to route log events over my customized “appender”? Yet more abstractions.

About these ads

2 Comments

  1. Posted November 21, 2012 at 11:01 am | Permalink | Reply

    Did you try setting up classloader isolation for your app so doesn’t use the included version? I’ve had to do this for every project deployed on jboss as5 and 6.

    in either jboss-web.xml for a war or jboss-app.xml for an ear.

    com.yourapp:loader=YourAppClassloader

    java2ParentDelegation=false

    I know it probably doesn’t help you, but as6 is kind of total crap. If you have the ability to upgrade as7 is a hundred times easier to work with.

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

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: