Bootstrap FreeKB - Java - Logging using java.util.logging
Java - Logging using java.util.logging

Updated:   |  Java articles

There are various ways to go about append events to a custom log file in Java.

Here is an example of how to append events to an application servers log using the java.util.logging logger.

import java.util.logging.*;

public class Main {

    private static final Logger logger = Logger.getLogger (Main.class.getName());

	public static void main(String[] args) {
		logger.info("Hello World");
	}
}

 

The application server logs should have something like this.

22-Feb-2023 02:51:23.233 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
22-Feb-2023 02:51:23.265 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-openssl-nio-8443"]
22-Feb-2023 02:51:23.272 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [798] milliseconds
22-Feb-2023 02:51:33.118 INFO [main] Main.main Hello World

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 64a43d in the box below so that we can be sure you are a human.