java.util.logging赢得';t记录到文件

java.util.logging赢得';t记录到文件,java,java.util.logging,Java,Java.util.logging,我正在努力让java.util.logging登录到一个文件,而不仅仅是Eclipse中的控制台 public class TestDefaultConfiguration { private static Logger logger = Logger.getLogger(TestDefaultConfiguration.class.getName()); public static void main(String[] args) { System.out.

我正在努力让
java.util.logging
登录到一个文件,而不仅仅是Eclipse中的控制台

public class TestDefaultConfiguration {

    private static Logger logger = Logger.getLogger(TestDefaultConfiguration.class.getName());

    public static void main(String[] args) {
        System.out.println("-- main method starts --");
        logger.info("an info msg");
        logger.warning("a warning msg!");
        logger.severe("a severe msg!");
    }
}
以下是属性:

C:\Program Files\Java\jre1.8.0_152\lib\logging.properties
我将默认属性文件编辑为:

.level= INFO
# default file output is in user's home directory.
#java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.pattern = C:/temp/test/MyLogFile2.log

java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
#java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
当我调试测试类时,我可以在
logger.manager.props
中看到这些属性被拾取。到目前为止,一切顺利

为什么在
C:/temp/test/MyLogFile2.log
中没有创建日志文件

不确定是否应添加Eclipse配置VM参数:

-Djava.util.logging.config.file="C:/Program Files/Java/jre1.8.0_152/lib/logging.properties"
但如果我这样做了,那也没什么区别


有什么建议吗?

从logging.properties中,您没有显示将处理程序附加到记录器的部分。这在文件中解释为注释

# "handlers" specifies a comma separated list of log Handler 
# classes.  These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# By default we only configure a ConsoleHandler, which will only
# show messages at the INFO and above levels.
handlers= java.util.logging.ConsoleHandler

# To also add the FileHandler, use the following line instead.
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
查看处理程序是否连接到根记录器

将以下行添加到属性文件:

handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler