Skip to content

Commit 8ecb480

Browse files
committed
munet: remove bad idea of shortening of logged cmd output
After a good deal of experience triaging issues with software that uses munet, it has become clear that truncating the debug level stdout and stderr values for cmd_status() in logging is a real nuisance and not worth the attempted tidiness. Signed-off-by: Christian Hopps <chopps@labn.net>
1 parent cb1124c commit 8ecb480

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

munet/base.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,25 @@ def shorten(s):
139139
return s
140140

141141

142-
def comm_result(rc, o, e):
143-
s = f"\n\treturncode {rc}" if rc else ""
144-
o = "\n\tstdout: " + shorten(o) if o and o.strip() else ""
145-
e = "\n\tstderr: " + shorten(e) if e and e.strip() else ""
146-
return s + o + e
142+
def block_quote(s):
143+
ss = s.strip()
144+
if "\n" not in ss:
145+
return " " + s.rstrip()
146+
s = "\n\t" + s.replace("\n", "\n\t")
147+
if s.endswith("\n\t"):
148+
s = s[:-2]
149+
else:
150+
s += "<EOF-NO-NEWLINE>"
151+
return s
152+
153+
154+
def comm_result(o, e):
155+
o = " stdout: " + block_quote(o) if o and o.strip() else ""
156+
e = " stderr: " + block_quote(e) if e and e.strip() else ""
157+
if o and e:
158+
return o + "\n" + e
159+
else:
160+
return o + e
147161

148162

149163
def proc_str(p):
@@ -1078,8 +1092,7 @@ def _cmd_status_finish(self, p, c, ac, o, e, raises, warn):
10781092
rc = p.returncode
10791093
self.last = (rc, ac, c, o, e)
10801094
if not rc:
1081-
resstr = comm_result(rc, o, e)
1082-
if resstr:
1095+
if resstr := comm_result(o, e):
10831096
self.logger.debug("%s", resstr)
10841097
else:
10851098
if warn:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "munet"
3-
version = "0.17.1"
3+
version = "0.17.2"
44
description = "A package to facilitate network simulations"
55
readme = {file = "README.org", content-type = "text/plain"}
66
requires-python = ">=3.9"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)