Skip to content

Feature: Add JSON structured logging output with --log-format flag #2453

@Dauliac

Description

@Dauliac

Description

Summary

Add a --log-format json flag to enable structured JSON logging for task execution output, making Task more suitable for automated log processing, monitoring systems, and observability pipelines.

Motivation

As an SRE working with monitoring and observability tooling, structured logs are essential for:

  • Log aggregation: Systems like ELK Stack, Splunk, Loki, or CloudWatch require structured logs for efficient querying and filtering
  • Automated parsing: CI/CD pipelines and automation scripts need reliable, machine-readable output
  • Observability: Monitoring tools can extract metrics and create dashboards from structured logs
  • Tracing: JSON logs integrate seamlessly with distributed tracing systems
  • Cost efficiency: Structured logs reduce storage and processing costs in log management platforms

Currently, Task outputs human-readable text logs, which are excellent for development but problematic for production monitoring and automated systems.

Proposed Solution

Add a new flag --log-format (or --output-format) with support for:

  • text (default): Current human-readable format
  • json: Structured JSON output

Example Usage

# Enable JSON logging
task build --log-format json

# Or via environment variable
export TASK_LOG_FORMAT=json
task build

Example JSON Output

{"timestamp":"2025-10-02T10:15:30.123Z","level":"info","task":"build","event":"task_started","message":"Starting task: build"}
{"timestamp":"2025-10-02T10:15:30.234Z","level":"info","task":"build","command":"go build -o app","event":"command_started"}
{"timestamp":"2025-10-02T10:15:32.456Z","level":"info","task":"build","command":"go build -o app","stdout":"building...","event":"command_output"}
{"timestamp":"2025-10-02T10:15:35.789Z","level":"info","task":"build","command":"go build -o app","exit_code":0,"duration_ms":3555,"event":"command_completed"}
{"timestamp":"2025-10-02T10:15:35.790Z","level":"info","task":"build","duration_ms":5667,"event":"task_completed","status":"success"}

Suggested JSON Schema

Each log entry should include:

Common fields:

  • timestamp: ISO8601 timestamp
  • level: Log level (info, warn, error, debug)
  • task: Task name being executed
  • event: Event type (see below)
  • message: Human-readable message

Event types:

  • task_started: When a task begins execution
  • task_completed: When a task finishes (includes status: success/failed)
  • task_skipped: When a task is skipped (cached/up-to-date)
  • command_started: Before running a command
  • command_output: Command stdout/stderr (with stream field: stdout/stderr)
  • command_completed: After command finishes (includes exit_code, duration_ms)
  • dependency_resolved: When a dependency task completes
  • variable_expanded: When variables are evaluated (debug level)

Context fields (when applicable):

  • command: The command being executed
  • exit_code: Command exit code
  • duration_ms: Duration in milliseconds
  • status: Success/failed status
  • error: Error message if applicable
  • stdout/stderr: Output streams
  • deps: Array of dependency task names
  • vars: Task variables (for debug level)

Environment:

  • Task version: Latest (v3.x)
  • Use case: SRE/DevOps monitoring and observability

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs triageWaiting to be triaged by a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions