Additional Java SE Packages

Formatter

The Formatter class in java.util.logging is used to control the output format of log messages. When a Logger sends a log record to a Handler, the handler uses a Formatter to convert the LogRecord into a human-readable string. Common Subclasses of Formatter Commomly Used Methods Simple Example with Built-in Formatters Output in simple_log.log: Problem Statement: …

Formatter Read More »

Basics of Formatters

In the Java Logging API (java.util.logging), a Formatter is used to convert a LogRecord into a human-readable string. Formatters decide how log messages appear—e.g., timestamped lines, JSON, XML, or custom formats. Formatters are essential when logs need to be stored, shared, or visualized clearly. Customize log output format Apply consistent structure across handlers (e.g., console, …

Basics of Formatters Read More »

StreamHandler

StreamHandler is a handler in Java’s logging API that writes log records to a given OutputStream. It is useful when you want to log messages to: A custom stream like ByteArrayOutputStream A Socket stream Any generic OutputStream (e.g., file, memory, network) However, it does not flush automatically, so you must call flush() or close() to …

StreamHandler Read More »

SocketHandler

SocketHandler is a logging handler in the java.util.logging package that sends log messages to a remote logging server using TCP sockets. This is useful for: Distributed systems Centralized logging Real-time monitoring It requires a logging server to receive and process logs (typically using SocketHandler + SocketHandlerServer or a custom SocketHandlerListener). Commonly Used Methods Simple Program …

SocketHandler Read More »

FileHandler

The FileHandler in java.util.logging is used to write log messages to disk files. It supports features like log rotation and appending to existing files. Key Features Writes logs to files. Can rotate log files based on size and limit. Can append to existing files. Works with formatters like SimpleFormatter or custom ones. Commonly Used Methods …

FileHandler Read More »

ConsoleHandler

The ConsoleHandler is a built-in logging handler in the java.util.logging package that writes log messages to the console (System.err by default).It is commonly used during development and debugging to quickly view log output. Key Features Writes logs to console in real time. Can be customized with formatters and log levels. Often used alongside or instead …

ConsoleHandler Read More »

LoggingMXBean

The LoggingMXBean is an interface in the java.lang.management package that allows monitoring and managing loggers in a Java application at runtime via JMX (Java Management Extensions). It provides a way to dynamically inspect and change logging configurations (like log levels) without restarting the application. Commonly Used Methods Simple Program Real-Time Log Level Management in a …

LoggingMXBean Read More »

LogManager

The LogManager class in the java.util.logging package is responsible for: Managing the global logging configuration. Creating and maintaining the Logger namespace. Loading configuration files (e.g., logging.properties). Controlling how loggers are initialized and accessed across the application. It acts as the central manager for all logging resources in a Java program. Commonly Used Methods Simple Program: …

LogManager Read More »

Scroll to Top