简体   繁体   中英

Java Logging - logging is done, where is my log file

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.

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

is the right code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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