import java.util.logging.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger("com.example.MyClass"); } LOGGER.setLevel(Level.INFO); import java.util.logging.ConsoleHandler; import java.util.logging.Level; ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.ALL); LOGGER.addHandler(consoleHandler); LOGGER.log(Level.INFO, "This is an information log message"); LOGGER.log(Level.WARNING, "This is a warning log message"); import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; public class LoggingExample { private static final Logger LOGGER = Logger.getLogger("com.example.LoggingExample"); public static void main(String[] args) { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.ALL); LOGGER.addHandler(consoleHandler); LOGGER.setLevel(Level.INFO); LOGGER.log(Level.INFO, "This is an information log message"); LOGGER.log(Level.WARNING, "This is a warning log message"); } } Aug 25, 2021 10:28:48 AM com.example.LoggingExample main INFO: This is an information log message Aug 25, 2021 10:28:48 AM com.example.LoggingExample main WARNING: This is a warning log message


上一篇:
下一篇:
切换中文