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:
+10
-2
@@ -28,7 +28,7 @@ import urllib.error
|
||||
import urllib.parse
|
||||
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
|
||||
# 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.
|
||||
TAG = "warpstore"
|
||||
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):
|
||||
@@ -63,8 +66,13 @@ def set_verbose(flag):
|
||||
VERBOSE = bool(flag)
|
||||
|
||||
|
||||
def set_log_stream(stream):
|
||||
global LOG_STREAM
|
||||
LOG_STREAM = stream
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"[{TAG}] {msg}", flush=True)
|
||||
print(f"[{TAG}] {msg}", file=LOG_STREAM, flush=True)
|
||||
|
||||
|
||||
def debug(msg):
|
||||
|
||||
Reference in New Issue
Block a user