import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) { LOGGER.setLevel(Level.INFO); LOGGER.addHandler(new ConsoleHandler()); LOGGER.info("Hello, LogManager!"); } }
import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) { LOGGER.log(Level.WARNING, "A warning message"); } }In this example, we use the log() method to log a WARNING-level message with the LOGGER instance. The java.util.logging package is part of the Java standard library, so it does not require any additional package or library.