Let an engine move its log off stdout

A graphical client needs data on stdout and nothing else, so `set_log_stream()`
lets an adapter send the human-readable log to stderr instead. `die()` already
wrote there; this is the rest of it.

One function and one module variable — the smallest thing that makes the stores
scriptable rather than only readable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 10:54:00 +02:00
co-authored by Claude Opus 5
parent c4a98e5d67
commit 10f7e88434
+10 -2
View File
@@ -28,7 +28,7 @@ import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
VERSION = "1.2.0" VERSION = "1.3.0"
# Bumped when the on-disk shape of state.json changes. v1 keyed `installed` by # Bumped when the on-disk shape of state.json changes. v1 keyed `installed` by
# bare software name; v2 keys by `<scope>:<name>`. # bare software name; v2 keys by `<scope>:<name>`.
@@ -51,6 +51,9 @@ class Skip(Exception):
# so two stores on one machine are told apart in a shared log. # so two stores on one machine are told apart in a shared log.
TAG = "warpstore" TAG = "warpstore"
VERBOSE = False VERBOSE = False
# Where the human-readable log goes. An engine asked for machine-readable output
# moves it to stderr, so stdout carries data and nothing else.
LOG_STREAM = sys.stdout
def set_tag(tag): def set_tag(tag):
@@ -63,8 +66,13 @@ def set_verbose(flag):
VERBOSE = bool(flag) VERBOSE = bool(flag)
def set_log_stream(stream):
global LOG_STREAM
LOG_STREAM = stream
def log(msg): def log(msg):
print(f"[{TAG}] {msg}", flush=True) print(f"[{TAG}] {msg}", file=LOG_STREAM, flush=True)
def debug(msg): def debug(msg):