java util logging.properties: How to log to two different files

前端 未结 5 2190
逝去的感伤
逝去的感伤 2020-12-11 19:15

I am placing a logging.properties in the WEB-INF/classes dir of tomcat

I would like to log to two different files. For example: org.pkg1 goes to one file and org.pkg

5条回答
  •  悲哀的现实
    2020-12-11 19:43

    Speaking of logging.properties configuration, I did not found any mechanism to use more that one appender. I made simple workaround that works for me.

    public class CustomAFileHandler extends FileHandler {
       public DebugFileHandler() throws IOException, SecurityException {
          super();
       }
    }
    
    public class CustomBFileHandler extends FileHandler {
       public DebugFileHandler() throws IOException, SecurityException {
          super();
       }
    }
    

    And my logging.properties

    ...
    handlers=.CustomAFileHandler, .CustomBFileHandler, java.util.logging.ConsoleHandler
    
    .CustomAFileHandler.level=ALL
    .CustomAFileHandler.pattern=%h/A%u.log
    .CustomAFileHandler.limit=50000
    .CustomAFileHandler.count=1 
    .CustomAFileHandler.formatter=java.util.logging.SimpleFormatter
    
    
    .CustomBFileHandler.level=ALL
    .CustomBFileHandler.pattern=%h/B%u.log
    .CustomBFileHandler.limit=50000
    .CustomBFileHandler.count=1 
    .CustomBFileHandler.formatter=java.util.logging.SimpleFormatter
    ...
    

提交回复
热议问题