Logging in Java

Last Updated : 23 Jan, 2026

Logging is the process of recording runtime information such as application flow, errors, warnings, and system events. It helps in debugging, monitoring, and maintaining applications without interrupting execution. In Java, logging is done using the built-in java.util.logging framework.

How Logging Works in Java

The following steps show how logging is typically performed in a Java application:

  • Create a Logger object
  • Select an appropriate log level (INFO, WARNING, SEVERE, etc.)
  • Write log messages using the logger
  • The LogManager centrally manages logging configuration and output

Log Levels

Log levels define the severity and importance of log messages. Each level is associated with a numeric value and there are 7 standard log levels and 2 special log levels. A log level must be specified to control how much information is recorded.

Standard Log Levels:

LevelValueUsed for
SEVERE1000Indicates some serious failure
WARNING900Potential Problem
INFO800General Info
CONFIG700Configuration Info
FINE500General developer info
FINER400Detailed developer info
FINEST300Specialized Developer Info

Special Log Levels:

OFFInteger.MAX_VALUECapturing nothing
ALLInteger.MIN_VALUECapturing Everything

Using ALL may generate very large logs because it records every possible detail of program execution

Java Logging Architecture

Java logging is centrally managed and consists of the following two main components:

1. LogManager

  • Controls the entire logging system
  • Manages logger instances and configuration
  • Only one LogManager exists per application

Syntax to access LogManager:

LogManager.getLogManager();

2. Logger

  • Used to create and write log messages
  • Supports multiple log levels (INFO, WARNING, SEVERE, etc.)
  • Usually created using the class name

Syntax:

Logger logger = Logger.getLogger(MyClass.class.getName());

Java also provides a global logger:

Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

Example: Basic Logging in Java

This example shows how to use Java's built-in Logger to record messages with different severity levels.

Java
import java.util.logging.Logger;

public class GFG {
    private static final Logger LOGGER = Logger.getLogger(GFG.class.getName());

    public static void main(String[] args) {
        LOGGER.info("Application started");
        LOGGER.severe("This is a severe error message");
    }
}

Output:

Dec 17, 2025 6:38:09 AM GFG main
INFO: Application started
Dec 17, 2025 6:38:09 AM GFG main
SEVERE: This is a severe error message

Explanation:

  • Logger.getLogger(...): creates a single logger instance for the GFG class.
  • LOGGER.info(): logs an INFO message to indicate normal program execution.
  • LOGGER.severe(): logs a SEVERE message for a serious error.
  • All log messages are handled and displayed by Java’s centralized logging system automatically.
Comment