import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void doSomething() { try { // some code that may throw an exception } catch (Exception e) { LOGGER.warn("An exception occurred: " + e.getMessage()); } } }
import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void doSomething() { // some code that may cause unexpected results LOGGER.warn("A warning occurred: something unexpected happened."); } }The Java Logger warn method is part of the java.util.logging package library.