import java.util.logging.Logger; public class LogExample { private static final Logger LOGGER = Logger.getLogger(LogExample.class.getName()); public static void main(String[] args) { LOGGER.info("Informational message"); } }
import java.util.logging.Logger; public class LogExample { private static final Logger LOGGER = Logger.getLogger(LogExample.class.getName()); public static void main(String[] args) { try { int result = 5 / 0; } catch (Exception e) { LOGGER.severe("Error: " + e.getMessage()); } } }In the above code, we are dividing a number by zero, which results in an ArithmeticException being thrown. We are then catching this exception and logging the error message with the Logger class. The java.util.logging Logger class is a part of the Java standard library, which means it is included in every Java installation. It is located under the java.util.logging package.