import java.util.logging.Logger; public class MyClass { private static final Logger logger = Logger.getLogger(MyClass.class.getName()); public static void main(String[] args) { logger.setLevel(Level.INFO); logger.info("This is an information message"); logger.warning("This is a warning message"); } }
import java.util.logging.Logger; public class MyClass { private static final Logger logger = Logger.getLogger(MyClass.class.getName()); public static void main(String[] args) { logger.setLevel(Level.SEVERE); logger.info("This is an information message"); logger.warning("This is a warning message"); logger.severe("This is a severe message"); } }This example sets the logging level to SEVERE. The logger captures only severe messages, ignoring the info and warning messages. The setLevel() method is found in the java.util.logging package library.