Design a Logging Framework

Intermediate · 20 min read · Low-Level Design, Case Studies: Core

Levels, appenders, formatters and async logging.

"Design a logger like Log4j/SLF4J" is a favourite because it's a pure LLD problem with no business domain to learn — the interviewer can focus entirely on abstractions, extensibility and concurrency. The standard decomposition (logger → appenders → formatters, filtered by level) is worth knowing cold.

What the interviewer expects

The full design in this lesson is longer than anything you'd write in one round. It's there so you understand the edge cases and can answer follow-up questions. In the round itself, aim for this:

1. Requirements

2. Class design

Responsibilities:

3. Implementation

The application thread only enqueues; I/O happens on the worker. Key decisions stated explicitly: bounded queue, drop policy by level, and drain on shutdown.

4. Patterns used

5. Extensions

Interview questions

  • Why use placeholders like logger.debug('x={}', x) instead of string concatenation?
  • How do you make logging not slow down the application?
  • How do multiple threads safely write to the same log file?

Further reading

Key takeaways

  • Logger decides whether, appenders decide where, formatters decide how.
  • Check the level before formatting; use placeholders.
  • Async appender = decorator + bounded producer–consumer queue with an explicit drop policy and drain on shutdown.
  • Hierarchical loggers inherit levels and pass events up (chain of responsibility).

Previous: Design an LRU Cache · Next: Design a Library Management System