Workflow Logging
Comprehensive workflow logging is essential for debugging, auditing, and monitoring production workflows.
6 min•By Priygop Team•Updated 2026
What to Log
- Workflow start: workflow ID, name, input, start timestamp
- Node entry: node name, input state, timestamp
- Node exit: node name, output condition, duration, timestamp
- Decisions: which branch was taken and why (the condition value)
- Errors: node name, error type, error message, retry count
- Human approvals: who approved/rejected, when, and what was approved
- Workflow complete: final status, total duration, last node, output
Structured Logging
Structured Logging
import json
import time
from datetime import datetime
class WorkflowLogger:
def __init__(self, workflow_id: str):
self.workflow_id = workflow_id
self.log = []
def _entry(self, event_type: str, **kwargs) -> dict:
entry = {
"workflow_id": self.workflow_id,
"timestamp": datetime.now().isoformat(),
"event": event_type,
**kwargs
}
self.log.append(entry)
print(json.dumps(entry, default=str))
return entry
def workflow_start(self, name: str, input_data: dict):
return self._entry("workflow_start", name=name, input_keys=list(input_data.keys()))
def node_start(self, node_name: str):
self._start_time = time.time()
return self._entry("node_start", node=node_name)
def node_end(self, node_name: str, condition: str):
duration = round(time.time() - self._start_time, 3)
return self._entry("node_end", node=node_name,
condition=condition, duration_seconds=duration)
def node_error(self, node_name: str, error: str, retry: int = 0):
return self._entry("node_error", node=node_name, error=error, retry=retry)
def workflow_end(self, status: str, output_summary: str = ""):
return self._entry("workflow_end", status=status, output=output_summary)
# Use in a workflow
logger = WorkflowLogger("WF-001")
logger.workflow_start("refund_processing", {"order_id": "ORD-123"})
logger.node_start("lookup_order")
time.sleep(0.05) # Simulate work
logger.node_end("lookup_order", "found")
logger.workflow_end("complete", "Refund issued successfully")
print(f"\nLog entries: {len(logger.log)}")Key Takeaways
- Comprehensive workflow logging is essential for debugging, auditing, and monitoring production workflows.
- Workflow start: workflow ID, name, input, start timestamp
- Node entry: node name, input state, timestamp
- Node exit: node name, output condition, duration, timestamp