import java.util.logging.*; Logger logger = Logger.getLogger("MyApplication"); try { // some operation that may throw an exception } catch (Exception e) { logger.log(Level.SEVERE, "An error occurred", e); }
import java.util.logging.*; Logger logger = Logger.getLogger("MyApplication"); String messageId = "MY_APP_ERROR_001"; try { // some operation that may throw an exception } catch (Exception e) { logger.logp(Level.SEVERE, this.getClass().getName(), "myMethod", messageId, e); }In this example, the logger instance logs a severe-level error message with a custom message ID "MY_APP_ERROR_001". The logp method is used to specify the source class and method of the logging message. The java Logger logError method is part of the standard java.util.logging package library.