monitor: convert to json-seq

Tweak the existing json progress to follow the `application/json-seq`
media type as outlined in rfc7464 [0],[1].

[0] https://datatracker.ietf.org/doc/html/rfc7464
[1] https://en.wikipedia.org/wiki/JSON_streaming#Record_separator-delimited_JSON:wqu
This commit is contained in:
Michael Vogt 2023-11-15 17:36:52 +01:00 committed by Ondřej Budai
parent 83dc625fc3
commit c6eaac278d
3 changed files with 10 additions and 8 deletions

View file

@ -289,8 +289,8 @@ class LogMonitor(BaseMonitor):
self.out.write(message)
class JSONProgressMonitor(BaseMonitor):
"""Monitor that prints the log output of modules wrapped in a JSON object with context and progress metadata"""
class JSONSeqMonitor(BaseMonitor):
"""Monitor that prints the log output of modules wrapped in json-seq objects with context and progress metadata"""
def __init__(self, fd: int, manifest: osbuild.Manifest):
super().__init__(fd)
@ -321,6 +321,8 @@ class JSONProgressMonitor(BaseMonitor):
if origin is not None:
self._context.origin = origin
line = LogLine(message=message, context=self._context, progress=self._progress)
# follow rfc7464 (application/json-seq)
self.out.write(u"\x1e")
json.dump(line.as_dict(), self.out)
self.out.write("\n")
self._context.origin = oo