Discussions

General J2EE: Problem with java.util.logging

  1. Problem with java.util.logging (3 messages)

    Hi all,

    I've two ears in a Weblogic server using java.util.logging (i'm not allowed to use anything else like Commons-Logging or Log4j) and i have a problem with the configuration of the logs of those ears.

    In each ear I read a configuration file (named xxxlog.properties, being xxx the name of the app) to make the java.util.Logging System write the messages in a different file (xxx.log). To read those configuration files, i'm using the java.util.logging.LogManager.readConfiguration(inputStream) method.

    Well, the problem is that when i only use one of the apps, everything goes ok, but when i use both apps, the log messages are wrotten in the incorrect output file.

    Any idea of how to solve this? I'm not allowed to use only one configuration file for the whole server, and must have one output file for each ear in the server...

    Thanks in advance.

    ---- Example configuration file (both are similar) ----
    handlers=java.util.logging.FileHandler
    .level=ALL

    # Handlers
    java.util.logging.FileHandler.pattern=/home/weblogic/log/l33.log
    java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
    java.util.logging.FileHandler.limit=5000000
    java.util.logging.FileHandler.count=1

    Threaded Messages (3)

  2. My guess is that you are invoking the LogManager every time you need to get handle to the logger class. Instead if you cache the Logger class once initially and keep using it, that wouldn't happen.

    Hope it helps.

    Rakesh.
  3. Reloading configuration[ Go to top ]

    My guess is that you are invoking the LogManager every time you need to get handle to the logger class. Instead if you cache the Logger class once initially and keep using it, that wouldn't happen.Hope it helps.Rakesh.

    I only invoke LogManager.readConfiguration once in each app. I think the problem is that this method calls java.util.Properties.load(inputStream), so the whole configuration is reloaded and I loose the older one because this second method overwrites the properties.

    So the question is: how can i change mi configuration files son each app logs to a different file? My classes have different packages in each app, so can i do something like this?

    xxx.level=ALL
    xxx.handler=java.util.logging.FileHandler
  4. logging configuration[ Go to top ]

    Hello,

    The LogManager.readConfiguration reinitialize the logging for the JVM, by reseting the previous configuration( see the source code for LogManager() in jdk 1.4),all previous settings got loosed, so is not suitable for your problem, unfortunatelly java.util.logging does not provide a mechanism for your problem, the solution is to make your own properties file for log configuration and configure dynamically your loggers/handlers at startup.
    I notice that it is possible to set different log level for
    each handler, something like:

    static Logger logger = Logger.getLogger(com.company_name);
    ...
    Handler fh = new FileHandler(logFileName);
    fh.setLevel(logFileLevel);
    fh.setFormatter(new SimpleFormatter());
    logger.addHandler(fh);
    ...

    Liviu Barsan