Listing A
import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.FileHandler; public class JavaLoggingExample { private static Logger logger = Logger.getLogger(JavaLoggingExample.class.getName()); public JavaLoggingExample () { try { FileHandler fileHandler1 = new FileHandler("logtest.txt"); logger.addHandler(fileHandler1); } catch(IOException ioe) { logger.log(Level.SEVERE, "Unable to create file handler.", ioe); } logger.log(Level.SEVERE, "This is a severe level message!"); logger.log(Level.SEVERE, "This is a second severe level message!"); } public void testLog() { logger.info("Message sent from method call."); } public static void main(String[] args) throws java.io.IOException { JavaLoggingExample example = new JavaLoggingExample(); example.testLog(); } }