Throughout my career, I've relied on System.out.println() to print application logs to the terminal. However, at one point, a fellow Java Developer Engineer suggested using the Logger class instead.
System
This method is handy when developing a basic application and needing a quick way to log messages.
// The main, basic, and simplest way to log
System.out.println("Something");
Logger
This approach becomes invaluable when working on larger applications that require more sophisticated logging.
import java.util.logging.Logger;
class TestLogging {
// Creating a new Logger object
private static Logger log = Logger.getLogger(Logger.class.getName());
public static void main(String[] args) {
System.out.println("Hello World");
log.info("Hello World!");
}
}
This is the output generated when running the application:
That's all!
Top comments (1)
About static initializers, the Java channel issues an alert:
youtube.com/shorts/52wIam7kkL4