import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void doSomething() { LOGGER.info("Information message"); LOGGER.warning("Warning message"); LOGGER.severe("Severe message"); } }
import java.util.logging.Level; import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void doSomething() { try { // do something that may throw an Exception } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception caught", e); } } }This example creates a Logger object with the name of the class and uses it to log an Exception with the SEVERE level. The java.util.logging package library provides classes and interfaces for logging messages.