import java.util.logging.*; public class MyClass { private static Logger logger = Logger.getLogger(MyClass.class.getName()); public void doSomething() { // some code logger.warning("Something may be wrong"); // more code } }
import java.util.logging.*; public class MyApp { private static final Logger logger = Logger.getLogger(MyApp.class.getName()); public static void main(String[] args) { // some code logger.warning("Startup problem detected"); // more code } }In this example, the Logger object is created for the main class of the application, and a warning message is logged during startup. Package library: java.util.logging.