Skip to content

Commit 827c6a6

Browse files
committed
Actually print logs from sable_services and sable_history
1 parent 396841e commit 827c6a6

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

irctest/basecontrollers.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import shutil
99
import socket
1010
import subprocess
11+
import sys
1112
import tempfile
1213
import textwrap
1314
import time
15+
import threading
1416
from typing import (
1517
IO,
1618
Any,
@@ -148,10 +150,39 @@ def kill(self) -> None:
148150
self._own_ports.remove((hostname, port))
149151

150152
def execute(
151-
self, command: Sequence[Union[str, Path]], **kwargs: Any
153+
self, command: Sequence[Union[str, Path]], proc_name: Optional[str], **kwargs: Any
152154
) -> subprocess.Popen:
153155
output_to = None if self.debug_mode else subprocess.DEVNULL
154-
return subprocess.Popen(command, stderr=output_to, stdout=output_to, **kwargs)
156+
proc_name = proc_name or command[0]
157+
kwargs.setdefault("stdout", output_to)
158+
kwargs.setdefault("stderr", output_to)
159+
stream_stdout = stream_stderr = None
160+
if kwargs["stdout"] in (None, subprocess.STDOUT):
161+
kwargs["stdout"] = subprocess.PIPE
162+
def stream_stdout():
163+
for line in proc.stdout:
164+
prefix = f"{time.time():.3f} {proc_name} ".encode()
165+
try:
166+
sys.stdout.buffer.write(prefix + line)
167+
except ValueError:
168+
# "I/O operation on closed file"
169+
pass
170+
if kwargs["stderr"] in (subprocess.STDOUT, None):
171+
kwargs["stdout"] = subprocess.PIPE
172+
def stream_stderr():
173+
for line in proc.stdout:
174+
prefix = f"{time.time():.3f} {proc_name} ".encode()
175+
try:
176+
sys.stdout.buffer.write(prefix + line)
177+
except ValueError:
178+
# "I/O operation on closed file"
179+
pass
180+
proc = subprocess.Popen(command, **kwargs)
181+
if stream_stdout is not None:
182+
threading.Thread(target=stream_stdout, name="stream_stdout").start()
183+
if stream_stderr is not None:
184+
threading.Thread(target=stream_stderr, name="stream_stderr").start()
185+
return proc
155186

156187

157188
class DirectoryBasedController(_BaseController):

irctest/controllers/sable.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def certs_dir() -> Path:
265265
{
266266
"target": "stdout",
267267
"level": "trace",
268-
"modules": [ "sable_history" ]
268+
"modules": [ "sable" ]
269269
}
270270
]
271271
}
@@ -350,7 +350,7 @@ def certs_dir() -> Path:
350350
{
351351
"target": "stdout",
352352
"level": "debug",
353-
"modules": [ "sable_services" ]
353+
"modules": [ "sable" ]
354354
}
355355
]
356356
}
@@ -476,6 +476,7 @@ def run(
476476
cwd=self.directory,
477477
preexec_fn=os.setsid,
478478
env={"RUST_BACKTRACE": "1", **os.environ},
479+
proc_name="sable_ircd ",
479480
)
480481
self.pgroup_id = os.getpgid(self.proc.pid)
481482

@@ -567,6 +568,7 @@ def run(self, protocol: str, server_hostname: str, server_port: int) -> None:
567568
cwd=self.server_controller.directory,
568569
preexec_fn=os.setsid,
569570
env={"RUST_BACKTRACE": "1", **os.environ},
571+
proc_name="sable_services",
570572
)
571573
self.pgroup_id = os.getpgid(self.proc.pid)
572574

@@ -610,6 +612,7 @@ def run(self, protocol: str, server_hostname: str, server_port: int) -> None:
610612
cwd=self.server_controller.directory,
611613
preexec_fn=os.setsid,
612614
env={"RUST_BACKTRACE": "1", **os.environ},
615+
proc_name="sable_history ",
613616
)
614617
self.pgroup_id = os.getpgid(self.proc.pid)
615618

0 commit comments

Comments
 (0)