Log4J LogManager

Discussion in 'Java' started by WJ, May 19, 2004.

  1. WJ

    WJ Guest

    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.
    WJ, May 19, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,752
    Alexandra Stehman
    Jan 19, 2004
  2. Colin Foulkes
    Replies:
    2
    Views:
    731
    Colin Foulkes
    Jan 29, 2004
  3. Alex Hunsley
    Replies:
    2
    Views:
    12,912
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  4. Rodolfo
    Replies:
    0
    Views:
    946
    Rodolfo
    Jul 12, 2004
  5. spiderboy
    Replies:
    2
    Views:
    462
Loading...

Share This Page