The Level
class in the java.util.logging
package defines a set of standard logging levels that indicate the severity of log messages. Loggers and handlers use these levels to decide what messages to log or ignore.
Commonly Used Methods

Standard Logging Levels

Simple Program Using Levels
import java.util.logging.*; public class SimpleLevelExample { public static void main(String[] args) { Logger logger = Logger.getLogger("MyLogger"); // Set the minimum level to INFO logger.setLevel(Level.INFO); logger.finest("This is FINEST"); // Not logged logger.finer("This is FINER"); // Not logged logger.fine("This is FINE"); // Not logged logger.config("This is CONFIG"); // Not logged logger.info("This is INFO"); // Logged logger.warning("This is WARNING"); // Logged logger.severe("This is SEVERE"); // Logged } }
Problem Statement:
LotusJavaPrince has built a Banking Alert System. Mahesh, the security officer, requires the system to classify logs based on severity:
- Informational messages for transactions.
- Warnings for unusual patterns.
- Severe messages for detected fraud attempts.
Only logs with Level.WARNING
or higher should be printed to the audit console.
import java.util.logging.*; class BankLogger { private Logger logger; public BankLogger() { logger = Logger.getLogger("BankAuditLogger"); // Set logger to log only WARNING and above logger.setLevel(Level.WARNING); ConsoleHandler handler = new ConsoleHandler(); handler.setLevel(Level.WARNING); logger.addHandler(handler); logger.setUseParentHandlers(false); } public void logTransaction(String user, double amount) { logger.info("Transaction by " + user + " of $" + amount); // Not logged } public void logUnusualActivity(String user) { logger.warning("Unusual login pattern detected for user: " + user); // Logged } public void logFraud(String user) { logger.severe("Fraud attempt detected for user: " + user); // Logged } } public class BankAuditSystem { public static void main(String[] args) { BankLogger audit = new BankLogger(); audit.logTransaction("Mahesh", 2500.00); audit.logUnusualActivity("Mahesh"); audit.logFraud("Mahesh"); } }
The Level
class is the backbone of Java’s logging system, enabling developers to classify log messages based on their severity and relevance. Using levels like INFO
, WARNING
, and SEVERE
, applications can filter log output, reduce noise, and focus on critical events.
By properly configuring levels for loggers and handlers, systems like banking, healthcare, or enterprise apps can maintain clean, secure, and actionable logs. It’s an essential tool for debugging, auditing, and maintaining application health.