Logging in Advance Java is used to record application events such as errors, warnings, and informational messages. It helps developers monitor application behavior and troubleshoot issues without using System.out.println().
java.util.loggingJava’s built-in logging framework uses the Logger class. Each logger is identified by a name, usually the class name. Log levels include:
// Import Logger class for logging support
import java.util.logging.Logger;
public class LoggingDemo {
// Create a logger instance for this class
private static final Logger logger = Logger.getLogger(LoggingDemo.class.getName());
public static void main(String[] args) {
// Log an informational message
logger.info("Application started successfully");
// Log a warning message
logger.warning("This is a warning log message");
// Log a severe error message
logger.severe("A severe error occurred");
}
}
When this program runs, log messages are printed to the console with timestamps and log levels. Only messages of level INFO and above are shown by default.
Click the buttons below to act as the Logger and generate simulated console output.