or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Log File Analyzer

Build a command-line tool that processes log files to extract and count error messages by severity level.

Requirements

Your tool should accept a log file path as a command-line argument using the -f or --file option. When no file is provided, the tool should read from standard input (stdin).

The tool should process the input line-by-line and:

  1. Parse each log line to extract the severity level (ERROR, WARN, INFO, DEBUG)
  2. Count the occurrences of each severity level
  3. Output a summary showing counts for each severity level in the format: LEVEL: count

Log lines follow this format: [TIMESTAMP] LEVEL: message

For example:

[2025-01-15 10:23:45] ERROR: Database connection failed
[2025-01-15 10:23:46] WARN: Retry attempt 1
[2025-01-15 10:23:47] INFO: Connection restored

The tool should handle large files efficiently by processing them line-by-line without loading the entire file into memory.

Test Cases

  • When processing a file with 3 ERROR lines, 2 WARN lines, and 1 INFO line, output shows: ERROR: 3, WARN: 2, INFO: 1 @test
  • When processing empty input, output shows zero counts for all levels @test
  • When reading from stdin with 2 DEBUG lines, output shows: DEBUG: 2 @test

Implementation

@generates

API

/**
 * Processes log file or stdin and counts severity levels
 * @param {string} filePath - Path to log file, or null for stdin
 * @param {function} callback - Called with severity counts object
 */
function analyzeLog(filePath, callback) {
  // Implementation
}

module.exports = { analyzeLog };

Dependencies { .dependencies }

cli { .dependency }

Provides command-line argument parsing and line-by-line input streaming capabilities.

@satisfied-by