Back to LLD explorer
Behavioral Patterns: Chain of Responsibility, Singleton

Logger

Easy

Problem Summary

Design a log framework supporting info, debug, and error levels directing messages to console, files, or database targets.

Functional Scope

  • Levels: INFO, DEBUG, ERROR.
  • Each logger in chain handles messages based on threshold levels.
  • Support multiple sinks: File, Console, and Database.

Entity-Relationship (ER) Schema

Logger [1] <---> [0..1] Logger (Next Link)
Logger [1] <---> [1..*] LogSink

Design Approach

Implement the Chain of Responsibility pattern. Link standard log handlers (Info -> Debug -> Error) so request propagation is automatic.

Core Classes & Models

Logger (Abstract base handler)InfoLogger, DebugLogger, ErrorLogger (Concrete handlers)LogSubject / LogSink (ConsoleSink, FileSink)
Code Blueprint
public abstract class Logger {
    protected Logger nextLogger;
    public void setNextLogger(Logger next) { this.nextLogger = next; }
    public abstract void write(String message);
}