Print capture
Forward print() / sys.stdout / sys.stderr writes to AxonPush as
agent.log events. Use this for AI agent projects where the agent (or its
tools) emits free-form output via print() — the AxonPush wizard wires
this up automatically for detected agent projects so that any print call
shows up in the trace timeline.
The tee stream always writes to the original console first, so your
existing terminal output is unchanged. It then buffers the output until it
sees a newline and emits one event per line, so multi-write print()
calls don’t get fragmented across events.
Installation
Section titled “Installation”pip install axonpushNo extras needed — stdlib only.
import osfrom axonpush import AxonPushfrom axonpush.integrations.print_capture import setup_print_capture
client = AxonPush( api_key=os.environ["AXONPUSH_API_KEY"], tenant_id=os.environ["AXONPUSH_TENANT_ID"],)
handle = setup_print_capture( client, channel_id=1, agent_id="my-agent", service_name="my-agent",)# Captured AND written to the original consoleprint("agent starting up")print("step 1: loaded tools = ['web_search', 'calculator']")print("step 2: calling model")
# Also captures writes to sys.stderrimport sysprint("warning: retrying after 429", file=sys.stderr)Restoring stdout/stderr
Section titled “Restoring stdout/stderr”handle.unpatch() # restores the original sys.stdout / sys.stderrAlways unpatch() in a finally: block (or use the handle at the end of a
with context) so that test teardown and subprocess spawning don’t inherit
the tee stream.
Events
Section titled “Events”| Field | Value |
|---|---|
identifier | stdout.write or stderr.write |
event_type | agent.log (default) or app.log if source="app" |
payload.body | The captured line (trailing newline stripped) |
payload.severityNumber / payload.severityText | INFO for stdout, ERROR for stderr |
payload.attributes | stream.name (stdout / stderr) |
payload.resource | service.name (if configured) |