Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default Java logging - log file location for FileHandler

    Hello,
    All logging configurations for my logger are taken from a logging.properties file, but I'd like to set the FileHandler's log file directory after loading the properties file. This is because the directory name is loaded from another properties file (called config.properties).
    I understand that the directory is part of the file name specified by "java.util.logging.FileHandler.pattern" property in the properties file, but I'd like to change that, without changing the logging.properties file for every run.

    How can the LogManager's properties be changed, once loaded using readConfiguration(InputStream) function?

    There is no logMan.setProperty() method or anything similar...

    Thanks
    Kfir

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    While you can't dynamically change properties, you can change your logging Handlers programatically to override the properties.

    Java Code:
    Logger logger = ....
    
    Handler[] handlers = logger.getHandlers();
    
    for(Handler h : handlers) {
      if(h instanceof FileHandler)
        logger.removeHandler(h);
    }
    
    FileHandler fh = new FileHandler(...);
    ...alter logging default level, formatter, etc if desired...
    logger.addHandler(fh);

  3. #3
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 03-06-2009, 12:40 AM
  2. Location of java class libraries on Sun
    By phudgens in forum New To Java
    Replies: 3
    Last Post: 02-05-2009, 05:45 AM
  3. Java Extract PDF data from location XY
    By Unite in forum Advanced Java
    Replies: 1
    Last Post: 06-30-2008, 02:31 PM
  4. Java Logging
    By vaswin in forum Advanced Java
    Replies: 0
    Last Post: 08-06-2007, 02:18 PM
  5. Java Logging
    By vignesh in forum Advanced Java
    Replies: 3
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •