Search⌘ K
AI Features

Solution: Normalize Logger Interfaces

Explore how to implement a LoggerAdapter that standardizes diverse logger interfaces in Node.js. Learn to unify console and custom loggers so all modules use a consistent interface without changing original code.

Solution explanation

  • Lines 2–9: We define customLogger to simulate a non-standard logging module.

    • It exposes logInfo() and logError() instead of console.log and console.error.

    • This mismatch represents the incompatible interfaces the adapter must unify.

  • Lines 12–14: The constructor of LoggerAdapter accepts a logger instance.

    • The adapter holds a reference to whichever logger it wraps.

    • This allows client code to use a consistent interface regardless of the underlying ...