import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) { LOGGER.info("Hello, World!"); } }
import java.util.logging.*; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) throws IOException { FileHandler handler = new FileHandler("mylog.txt"); LOGGER.addHandler(handler); LOGGER.info("Log message to file!"); } }
import java.util.logging.*; import java.util.logging.SocketHandler; public class MyLogger { private static final Logger LOGGER = Logger.getLogger(MyLogger.class.getName()); public static void main(String[] args) throws IOException { SocketHandler handler = new SocketHandler("localhost", 9876); LOGGER.addHandler(handler); LOGGER.info("Log message to remote server!"); } }This code logs a message "Log message to remote server!" to a remote server on localhost with port number 9876. The SocketHandler class is used to send log messages over a network socket. In conclusion, the Java Logger class is part of the java.util.logging package included in the JDK, and it is a useful utility for generating and outputting log messages to various destinations such as console, files or remote servers.