3 Replies Latest reply: Aug 20, 2009 8:44 PM by 807580 RSS

    java Logging config file for multiple FileHandlers

    807580
      Is it possible to have multiple fileHandler configurations in the log properties file ? For me, I see only one file getting created..
      I basically want 3 log files with log information from Backend code, UI code and for events.
      Please suggest what is wrong with this.
      com.mylog.handlers = java.util.logging.FileHandler, java.util.logging.FileHandler, java.util.logging.FileHandler
      
      ############################################################
      # Handler specific properties.
      # Describes specific configuration info for Handlers.
      ############################################################
      # default file output is in user's home directory.
      java.util.logging.FileHandler.pattern = %h/log/bakend%u.log
      java.util.logging.FileHandler.filter = MyBkendLogFilter
      java.util.logging.FileHandler.limit = 50000
      java.util.logging.FileHandler.count = 1
      java.util.logging.FileHandler.formatter = MyLogFormatter
      
      
      java.util.logging.FileHandler.pattern = %h/log/ui%u.log
      java.util.logging.FileHandler.filter = MyUILogFilter
      java.util.logging.FileHandler.limit = 50000
      java.util.logging.FileHandler.count = 1
      java.util.logging.FileHandler.formatter = MyLogFormatter
      
      java.util.logging.FileHandler.pattern = %h/log/event%u.log
      java.util.logging.FileHandler.filter = MyEventLogFilter
      java.util.logging.FileHandler.limit = 50000
      java.util.logging.FileHandler.count = 1
      java.util.logging.FileHandler.formatter = MyLogFormatter
        • 1. Re: java Logging config file for multiple FileHandlers
          807580
          That config data is in the wrong format. You use a comma-separated list of formatters, etc. You don't list things twice to get a second handler/formatter/whatever; presumably that would just overwrite the previous assignment. Actually I think there are other problems with that format but I can't recall the details; google for the spec and experiment.
          • 2. Re: java Logging config file for multiple FileHandlers
            807580
            I picked up this format from the jre/lib/logging.properties, that has two handlers, consoleHandler and fileHandler.

            Yes, it is overwriting it.
            In the code, I can always add multiple FileHandlers to the Logger using,
            myLogger = new Logger("myLog");
            FileHandler bakendLog = new FileHandler("bk%u.log");
            bakendLog.setFilter(new BkendLogFilter());
            myLogger.addHandler(bakendLog);
            
            FileHandler eventLog = new FileHandler("event%u.log");
            eventLog.setFilter(new EventLogFilter());
            myLogger.addHandler(eventLog);
            
            FileHandler uiLog = new FileHandler("ui%u.log");
            uiLog.setFilter(new UILogFilter());
            myLogger.addHandler(uiLog);
            I wanted to know how to do that using the config file.
            • 3. Re: java Logging config file for multiple FileHandlers
              807580
              Sorry, didn't see what you meant before. As far as I can see there's no way to configure multiple file handlers in the config file.