or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

CLI Logger with Environment-Based Color Control

Build a simple CLI logging utility that respects standard environment variables to control color output. The logger should automatically adapt to different environments (CI systems, terminals with disabled colors, forced color environments) and provide multiple log levels with appropriate coloring.

Requirements

Log Levels

The logger must support four log levels, each with distinct visual styling:

  • info: Display messages in cyan
  • success: Display messages in green
  • warning: Display messages in yellow
  • error: Display messages in red

Environment Variable Handling

The logger must respect standard environment variables that control color output:

  • When NO_COLOR is set (any value), all color output must be disabled
  • When FORCE_COLOR is set (any value), color output must be enabled even in non-TTY environments
  • When CI is set (any value), color output should be enabled to support CI environment logs
  • The logger should handle the TERM=dumb case appropriately

Configuration Support

The logger should provide a way to manually override automatic color detection for testing purposes or custom configurations.

Test Cases

  • When NO_COLOR=1, calling logger.error("Failed") outputs plain text without ANSI codes @test
  • When FORCE_COLOR=1, calling logger.success("Done") includes green ANSI codes even if output is not to a TTY @test
  • When no environment variables are set, calling logger.info("Starting") produces cyan-colored output if supported @test
  • Manual color override using a configuration function disables colors when explicitly set to false @test

Implementation

@generates

API

/**
 * Logger object with methods for different log levels
 */
const logger = {
  /**
   * Log an informational message
   * @param {string} message - The message to log
   */
  info(message) {},

  /**
   * Log a success message
   * @param {string} message - The message to log
   */
  success(message) {},

  /**
   * Log a warning message
   * @param {string} message - The message to log
   */
  warning(message) {},

  /**
   * Log an error message
   * @param {string} message - The message to log
   */
  error(message) {}
};

/**
 * Create a logger instance with custom color configuration
 * @param {boolean} enableColors - Whether to enable color output
 * @returns {object} Logger object with info, success, warning, error methods
 */
function createLogger(enableColors) {}

module.exports = { logger, createLogger };

Dependencies { .dependencies }

picocolors { .dependency }

Provides terminal color formatting with automatic environment variable support for NO_COLOR, FORCE_COLOR, CI, and TERM detection.