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:
| Level | Value | Used for |
|---|---|---|
| SEVERE | 1000 | Indicates some serious failure |
| WARNING | 900 | Potential Problem |
| INFO | 800 | General Info |
| CONFIG | 700 | Configuration Info |
| FINE | 500 | General developer info |
| FINER | 400 | Detailed developer info |
| FINEST | 300 | Specialized Developer Info |
Special Log Levels:
| OFF | Integer.MAX_VALUE | Capturing nothing |
| ALL | Integer.MIN_VALUE | Capturing 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.
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.