Add logging to stderr

This commit is contained in:
László Károlyi 2024-08-06 22:55:16 +02:00
parent 3d0b7e1b24
commit d230f8cfde
Signed by: karolyi
GPG key ID: 2DCAF25E55735BFE

View file

@ -9,6 +9,7 @@ from signal import SIGTERM, signal
from socket import AF_INET6, IPPROTO_IPV6, IPV6_V6ONLY, socket
from sqlite3 import connect
from string import ascii_lowercase
from sys import stderr
from tempfile import gettempdir
from threading import Thread
from types import FrameType
@ -23,6 +24,11 @@ graph_printf %3.0lf
"""
def _log_message(message: str) -> None:
'Do a simple log on `stderr`.'
stderr.write(f'=== {message}\n')
class _JailInfo(NamedTuple):
id: int
name: str
@ -130,7 +136,7 @@ server = DualStackThreadingHttpServer(
def shutdown(signalnum: int, frame: FrameType | None):
'Shut down upon SIGTERM.'
print('Shutting down.')
_log_message('Shutting down.')
server.shutdown()
@ -138,10 +144,10 @@ if __name__ == '__main__':
signal(signalnum=SIGTERM, handler=shutdown)
run_thread = Thread(
target=server.serve_forever, kwargs=dict(poll_interval=1))
print('Serving.')
_log_message('Serving.')
run_thread.start()
try:
run_thread.join()
except KeyboardInterrupt:
pass
print('Server is shut down.')
_log_message('Server is shut down.')