import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void myMethod() { LOGGER.info("This is an info message"); } }
import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void myMethod() { LOGGER.setLevel(Level.WARNING); LOGGER.info("This is an info message"); LOGGER.warning("This is a warning message"); } }In this example, we set the log level to WARNING, which means that only messages with this level or higher (such as SEVERE) will be logged. We then log both an info message and a warning message, but only the warning message will be logged. Examples like these can be found in the java.util.logging package library.