Log4J LogManager

W

WJ

I can't find a group that's more dedicated to log4j. If there's one, I'd
appreciate the name.

Our app server has several web apps running on it. We'd like to deploy
log4j in all of them. However, we're running into an issue.

We put the log4j jar file in the common lib dir that all apps access.

Each app can add loggers and appenders dynamically and set the threshold.
This is done by reading values dynamically out of a
database. When a "refresh" method is called, it iterates through the
loggers, removes existing appenders and re-creates them.

I did this because I typically have the level set to error and fatal for the
console and rolling file. But if there's an issue, I'll drop
the level down to debug for a certain package only. Also, I only want that
to go into a rolling file, not the console.

I iterate through the loggers like this:

for(Enumeration
enum=Logger.getRoot().getLoggerRepository().getCurrentLoggers();
enum.hasMoreElements();)

Then I iterate through each appender on that logger and remove the appender.
Everything works great.

Except:

The LogManager seems to span applications. So if App A and App B both use
this technique, they are resetting each other's loggers.

I've done a lot of reading and two work arounds seem to be in place.

1. I put the log4j.jar in the local lib for each app. I really don't want
to do this, but it may be the only answer thus far.

2. I create a ContextualLoggerRepository and set it like
LogManager.setRepositorySelector(new ContextualLoggerRepository(), guard);

where the guard is just a simple obj. The problem with this is if App A
runs this, and App B tries to reset it's loggers, I get an error saying
App B tried to reset the loggers without possessing the guard.

Is there a way that will force a "local" LogManager for each application?
Is there a site that has some write ups on this? I've read most of the
returns from google.

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top