Zaira
Posted on June 11, 2024
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!
💖 💪 🙅 🚩
Zaira
Posted on June 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.