0

I am using java.util.logging, NetBeans IDE and Glassfish Server.

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. 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! Please help.

4

1 に答える 1

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

は正しいコードです。

于 2012-05-31T18:36:09.077 に答える