import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) { Handler[] handlers = LOGGER.getHandlers(); for (Handler handler : handlers) { System.out.println(handler.getClass().getName()); } } }
import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) throws Exception { FileHandler handler = new FileHandler("mylog.log"); LOGGER.addHandler(handler); LOGGER.info("Hello, world!"); } }In this example, we're adding a new FileHandler to our logger instance and logging an info message. The logs will be written to a file named "mylog.log". Both of these examples use the java.util.logging package library.