Configuring Java FileHandler Logging to create directories if they do not exist

后端 未结 5 788
既然无缘
既然无缘 2020-12-17 15:45

I\'m trying to configure the Java Logging API\'s FileHandler to log my server to a file within a folder in my home directory, but I don\'t want to have to create those direc

5条回答
  •  借酒劲吻你
    2020-12-17 16:18

    I generally try to avoid static code but to work around this limitaton here is my approach that worked on my project just now.

    I subclassed java.util.logging.FileHandler and implemented all constructors with their super calls. I put a static block of code in the class that creates the folders for my app in the user.home folder if they don't exist.

    In my logging properties file I replaced java.util.logging.FileHandler with my new class.

提交回复
热议问题