Solution: Add Feature-Flagged Logger Instantiation
Explore applying the factory design pattern to dynamically create logger instances driven by runtime feature flags. Understand how to map feature flags to interchangeable logger classes and centralize creation logic to enable flexible and maintainable Node.js services.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 1–11: We define two interchangeable logger classes:
FileLoggerandRemoteLogger.Both implement a
.log()method, ensuring consistent behavior for consumers regardless of which one is used.FileLoggersimulates local file logging, whileRemoteLoggerrepresents a new network-based logging service.
...