-
-
Notifications
You must be signed in to change notification settings - Fork 741
Open
Labels
state: needs triageWaiting to be triaged by a maintainer.Waiting to be triaged by a maintainer.
Description
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 formatjson
: 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 timestamplevel
: Log level (info, warn, error, debug)task
: Task name being executedevent
: Event type (see below)message
: Human-readable message
Event 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 (withstream
field: 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:
- Task version: Latest (v3.x)
- Use case: SRE/DevOps monitoring and observability
Metadata
Metadata
Assignees
Labels
state: needs triageWaiting to be triaged by a maintainer.Waiting to be triaged by a maintainer.