Problem: Normalize Logger Interfaces
Problem statement
Your team’s codebase uses two different logging systems across services:
Some modules use the native
consoleobject (console.log,console.error).Others rely on a custom in-house logger with
logInfo()andlogError()methods.
The inconsistency causes confusion and brittle integrations. You’ve been tasked to create a unified adapter so that the rest of the system can use a single, predictable interface.
Goal
Implement a LoggerAdapter class that wraps either console or customLogger and exposes these two methods:
.info(message)→ routes to the correct info-level method.error(message)→ routes to the correct error-level method
Constraints
The adapter must delegate to the correct underlying method (
logInfoorconsole.log,logErrororconsole.error).Do not modify the original logger implementations.
The calling code should always use the same
LoggerAdapterinterface.
Sample output
The examples below illustrate what the output should look like:
const consoleLogger = new LoggerAdapter(console);const internalLogger = new LoggerAdapter(customLogger);consoleLogger.info('Server started');internalLogger.info('Server started');consoleLogger.error('Failed to connect');internalLogger.error('Failed to connect');/* Expected output:Server startedcustomLogger info: Server startedFailed to connectcustomLogger error: Failed to connect*/
Good luck trying the problem! If you’re unsure how to proceed, check the “Solution” tab above.
Problem: Normalize Logger Interfaces
Problem statement
Your team’s codebase uses two different logging systems across services:
Some modules use the native
consoleobject (console.log,console.error).Others rely on a custom in-house logger with
logInfo()andlogError()methods.
The inconsistency causes confusion and brittle integrations. You’ve been tasked to create a unified adapter so that the rest of the system can use a single, predictable interface.
Goal
Implement a LoggerAdapter class that wraps either console or customLogger and exposes these two methods:
.info(message)→ routes to the correct info-level method.error(message)→ routes to the correct error-level method
Constraints
The adapter must delegate to the correct underlying method (
logInfoorconsole.log,logErrororconsole.error).Do not modify the original logger implementations.
The calling code should always use the same
LoggerAdapterinterface.
Sample output
The examples below illustrate what the output should look like:
const consoleLogger = new LoggerAdapter(console);const internalLogger = new LoggerAdapter(customLogger);consoleLogger.info('Server started');internalLogger.info('Server started');consoleLogger.error('Failed to connect');internalLogger.error('Failed to connect');/* Expected output:Server startedcustomLogger info: Server startedFailed to connectcustomLogger error: Failed to connect*/
Good luck trying the problem! If you’re unsure how to proceed, check the “Solution” tab above.