Scenario:
You are required to implement a logging system in a NestJS application that allows switching between different logging implementations based on an environment variable. The system should use dependency injection to manage these implementations.
Task:
-
Interface Definition:
- Define an interface
ILoggerwith a single methodlogError.
- Define an interface
-
Concrete Implementations:
- Implement at least two concrete classes that adhere to the
ILoggerinterface. For example,ConsoleLoggerandFileLogger.
- Implement at least two concrete classes that adhere to the
-
Dependency Injection:
- Set up these implementations to be injected into the application at startup.
- Use an environment variable to determine which implementation should be used.
-
Configuration:
- Demonstrate how the application can switch between these implementations based on the value of the environment variable.
-
Testing:
- Set up a unit test framework of your choice (e.g., Jest).
- Write unit tests to verify the behavior of your logging implementations and the configuration logic.
Expectations:
- Clean Code: Ensure your code is clean, well-organized, and adheres to best practices.
- Good Commit Pattern: Follow a clear and logical commit pattern.
- Accurate Implementation: The implementation should meet the requirements accurately.
- Testing: Show how the implementation can be tested, and provide example tests.
Deliverables:
- Source code with the interface and implementations.
- Configuration setup demonstrating environment-based switching.
- Unit tests for the implementations and configuration logic.
- A brief documentation of your thought process and any assumptions made.
Time Frame:
You have about 12 hours from task reception to complete this task.