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
Description
Summary
Add a
--log-format jsonflag 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:
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 formatjson: Structured JSON outputExample Usage
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 timestamplevel: Log level (info, warn, error, debug)task: Task name being executedevent: Event type (see below)message: Human-readable messageEvent types:
task_started: When a task begins executiontask_completed: When a task finishes (includesstatus: success/failed)task_skipped: When a task is skipped (cached/up-to-date)command_started: Before running a commandcommand_output: Command stdout/stderr (withstreamfield: stdout/stderr)command_completed: After command finishes (includesexit_code,duration_ms)dependency_resolved: When a dependency task completesvariable_expanded: When variables are evaluated (debug level)Context fields (when applicable):
command: The command being executedexit_code: Command exit codeduration_ms: Duration in millisecondsstatus: Success/failed statuserror: Error message if applicablestdout/stderr: Output streamsdeps: Array of dependency task namesvars: Task variables (for debug level)Environment: