简体   繁体   English

Java日志记录-日志记录完成,我的日志文件在哪里

[英]Java Logging - logging is done, where is my log file

I am using java.util.logging, NetBeans IDE and Glassfish Server. 我正在使用java.util.logging,NetBeans IDE和Glassfish服务器。

I have loaded a custom log properties file. 我已经加载了自定义日志属性文件。 Application is doing the logging but the log file is missing. 应用程序正在执行日志记录,但是缺少日志文件。

handlers = java.util.logging.FileHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = INFO
java.util.logging.ConsoleHandler.level = ALL

is my logfile properties and following is the code to load it: 是我的日志文件属性,以下是加载它的代码:

Properties props = new Properties();
Logger log = Logger.getLogger(ServiceInvoker.class.getName());
log.setLevel(Level.ALL);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("log.properties");
File file = new File(resource.toURI());
FileInputStream fis = new FileInputStream(file);
props.load(fis);
LogManager.getLogManager().readConfiguration(fis);

I checked for the log file at location C:\\Users\\user_name. 我在位置C:\\ Users \\ user_name中检查了日志文件。 When I don't use this logging, I can see the log messages in NetBeans server console, when I use this logging there is no message in console and also the log file is missing! 当我不使用此日志记录时,我可以在NetBeans服务器控制台中看到日志消息,当我使用此日志记录时,控制台中没有消息,并且日志文件也丢失了! Please help. 请帮忙。

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream is = classLoader.getResourceAsStream("log.properties");
        LogManager.getLogManager().readConfiguration(is);

is the right code. 是正确的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM