or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Cross-Platform CLI Logger

Build a command-line logging utility that intelligently formats output based on the terminal environment, supporting multiple output destinations with platform-specific behavior.

Requirements

Create a logger that:

  1. Auto-detects terminal capabilities - The logger should automatically determine whether the current environment supports colored output and adjust formatting accordingly.

  2. Supports multiple output modes - The logger must support writing to:

    • Standard output (with automatic color detection)
    • Log files (always plain text, no color codes)
    • Both simultaneously
  3. Provides configurable color control - Users should be able to:

    • Force colors on even when auto-detection would disable them
    • Force colors off even when auto-detection would enable them
    • Use the default auto-detection
  4. Handles platform differences - The implementation should properly detect and handle:

    • Windows command prompt and PowerShell
    • Unix/Linux TTY environments
    • Non-TTY environments (pipes, redirects)
    • CI/CD environments

API

The logger should expose:

/**
 * Creates a new logger instance with the specified configuration.
 *
 * @param {Object} options - Configuration options
 * @param {boolean} [options.fileOutput=false] - Whether to write to a log file
 * @param {string} [options.filePath='./output.log'] - Path to log file if fileOutput is true
 * @param {boolean|null} [options.forceColor=null] - Override color detection: true=force on, false=force off, null=auto-detect
 * @returns {Logger} A logger instance
 */
function createLogger(options);

/**
 * Logger instance methods
 */
class Logger {
  /**
   * Logs an informational message in cyan
   */
  info(message);

  /**
   * Logs a success message in green
   */
  success(message);

  /**
   * Logs a warning message in yellow
   */
  warning(message);

  /**
   * Logs an error message in red
   */
  error(message);

  /**
   * Returns whether colors are currently enabled
   */
  isColorEnabled();
}

Test Cases

  • Creating a logger with default settings uses auto-detected color support @test
  • Logger with forceColor: false disables colors even in color-capable terminals @test
  • Logger with forceColor: true enables colors even in non-color terminals @test
  • File output always writes plain text without color codes @test

Implementation

@generates

Dependencies { .dependencies }

picocolors { .dependency }

Provides terminal color formatting support with automatic platform detection.