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

前端 未结 5 2189
逝去的感伤
逝去的感伤 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:28

    Having the same problem myself with java.util.logging and not quite satisfied with the given answers, I just found in the documentation:

    2.2 Changing the Configuration

    Here's a small program that dynamically adjusts the logging configuration to send output to a specific file and to get lots of information on wombats. The pattern "%t" means the system temporary directory.

    public static void main(String[] args) {
            Handler fh = new FileHandler("%t/wombat.log");
            Logger.getLogger("").addHandler(fh);
            Logger.getLogger("com.wombat").setLevel(Level.FINEST);
            ...
        }
    

    So, it seems you can't do it just from the .properties file as can't instantiate several appenders, but you can do it programmatically. Also it should be possible using the LoggerManager

提交回复
热议问题