import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class.getName()); public void someMethod() { LOGGER.info("This is a log statement"); } }
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 someMethod(String param1, int param2) { LOGGER.log(Level.INFO, "Logging with parameters: {0}, {1}", new Object[] { param1, param2 }); } }
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 someMethod() { try { // some code that may throw an exception } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception occurred", e); } } }In this example, we catch an exception and log it at the `SEVERE` level using the `log` method. The third parameter is the exception object that provides detailed information about the error. These examples demonstrate how to use the Java logging API from the java.util.logging package.