import java.util.logging.Handler; import java.util.logging.Logger; public class MyLogger { private static final Logger logger = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) { System.out.println("Start logging..."); // create a new handler and add it to the logger Handler myHandler = new MyHandler(); logger.addHandler(myHandler); // log some messages logger.warning("This is a warning message!"); logger.info("This is an info message!"); // remove the handler from the logger logger.removeHandler(myHandler); // log some more messages logger.warning("This is another warning message!"); logger.info("This is another info message!"); System.out.println("End logging."); } } class MyHandler extends Handler { public void publish(java.util.logging.LogRecord record) { System.out.println(record.getMessage()); } public void flush() {} public void close() {} }In this example, we create a logger and add a custom handler to it. We then log some messages with the logger and remove the handler from the logger. Finally, we log some more messages to demonstrate that the second set of messages is not captured by the removed handler. The java.util.logging package is part of the Java Platform Standard Edition (Java SE) library, which is included with the Java Development Kit (JDK).