docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a command-line logging utility that can output formatted log messages with different severity levels. The logger must support configuration-based color control, allowing users to enable or disable color output via a configuration file, independent of terminal capabilities.
Your implementation must support:
Multiple Log Levels: The logger should support at least three severity levels:
info: Informational messageswarn: Warning messageserror: Error messagesConfiguration-Based Color Control: The logger must read a configuration file (config.json) that contains a boolean enableColors field. This configuration should control whether log output includes color formatting, regardless of terminal capabilities.
Color Formatting: When colors are enabled:
Consistent API: The logger should work the same way whether colors are enabled or disabled - only the output formatting should differ.
Create the following files:
logger.jsThe main logger module that:
createLogger(config) function that returns a logger instanceinfo(message), warn(message), and error(message)config.jsonA JSON configuration file with the structure:
{
"enableColors": true
}logger.test.js { .test }Test file containing the following test cases:
Test 1: @test
When enableColors is true, calling logger.info("test message") should output text that includes ANSI color escape codes (specifically the cyan color code \x1b[36m).
Test 2: @test
When enableColors is false, calling logger.info("test message") should output plain text without any ANSI escape codes (no \x1b[ sequences).
Test 3: @test
When enableColors is true, the logger should format different severity levels with different colors:
logger.warn("warning") should include yellow color codes (\x1b[33m)logger.error("error") should include red color codes (\x1b[31m)Provides terminal color formatting support.
const createLogger = require('./logger');
const config = require('./config.json');
const logger = createLogger(config);
logger.info('Application started');
logger.warn('Configuration file is outdated');
logger.error('Failed to connect to database');