summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-07-21 13:54:47 +0300
committerMaxim Devaev <[email protected]>2022-07-21 13:54:47 +0300
commitca87bd66d7d6734936ca941a09cb24758061247a (patch)
treecc36598a7a22b2e026ef70c49cb807779ed9cb46 /kvmd/apps
parentaf4eb772318de6553363730a51f0b800fe001aa6 (diff)
improved vnc logging
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/vnc/rfb/__init__.py26
-rw-r--r--kvmd/apps/vnc/server.py28
2 files changed, 27 insertions, 27 deletions
diff --git a/kvmd/apps/vnc/rfb/__init__.py b/kvmd/apps/vnc/rfb/__init__.py
index da984a4b..5d7847a9 100644
--- a/kvmd/apps/vnc/rfb/__init__.py
+++ b/kvmd/apps/vnc/rfb/__init__.py
@@ -94,7 +94,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
async def _run(self, **coros: Coroutine) -> None:
logger = get_logger(0)
- logger.info("[entry] %s: Starting client tasks ...", self._remote)
+ logger.info("%s [entry]: Starting client tasks ...", self._remote)
tasks = list(map(asyncio.create_task, [ # type: ignore # Я хз, почему github action фейлится здесь
self.__wrapper(name, coro)
for (name, coro) in {"main": self.__main_task_loop(), **coros}.items()
@@ -106,7 +106,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
await self._close()
- logger.info("[entry] %s: Connection closed", self._remote)
+ logger.info("%s [entry]: Connection closed", self._remote)
async def __wrapper(self, name: str, coro: Coroutine) -> None:
logger = get_logger(0)
@@ -114,14 +114,14 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
await coro
raise RuntimeError("Subtask just finished without any exception")
except asyncio.CancelledError:
- logger.info("[%s] %s: Cancelling subtask ...", name, self._remote)
+ logger.info("%s [%s]: Cancelling subtask ...", self._remote, name)
raise
except RfbConnectionError as err:
- logger.info("[%s] %s: Gone: %s", name, self._remote, err)
+ logger.info("%s [%s]: Gone: %s", self._remote, name, err)
except (RfbError, ssl.SSLError) as err:
- logger.error("[%s] %s: Error: %s", name, self._remote, err)
+ logger.error("%s [%s]: Error: %s", self._remote, name, err)
except Exception:
- logger.exception("[%s] %s: Unhandled exception", name, self._remote)
+ logger.exception("%s [%s]: Unhandled exception", self._remote, name)
async def __main_task_loop(self) -> None:
await self.__handshake_version()
@@ -225,7 +225,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
except ValueError:
raise RfbError(f"Invalid version response: {response!r}")
self.__rfb_version = (3 if version == 5 else version)
- get_logger(0).info("[main] %s: Using RFB version 3.%d", self._remote, self.__rfb_version)
+ get_logger(0).info("%s [main]: Using RFB version 3.%d", self._remote, self.__rfb_version)
# =====
@@ -250,7 +250,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
raise RfbError(f"Invalid security type: {sec_type}")
(sec_name, handler) = sec_types[sec_type]
- get_logger(0).info("[main] %s: Using %s security type", self._remote, sec_name)
+ get_logger(0).info("%s [main]: Using %s security type", self._remote, sec_name)
await handler()
async def __handshake_security_vencrypt(self) -> None: # pylint: disable=too-many-branches
@@ -294,7 +294,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
raise RfbError(f"Invalid VeNCrypt auth type: {auth_type}")
(auth_name, tls, handler) = auth_types[auth_type]
- logger.info("[main] %s: Using %s auth type", self._remote, auth_name)
+ logger.info("%s [main]: Using %s auth type", self._remote, auth_name)
if tls:
assert self.__tls_ciphers, (self.__tls_ciphers, auth_name, tls, handler)
@@ -306,7 +306,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
assert self.__x509_cert_path
ssl_context.load_cert_chain(self.__x509_cert_path, (self.__x509_key_path or None))
ssl_context.set_ciphers(self.__tls_ciphers)
- logger.info("[main] %s: Starting TLS (%s) ...", self._remote, tls_str)
+ logger.info("%s [main]: Starting TLS (%s) ...", self._remote, tls_str)
await self._start_tls(ssl_context, self.__tls_timeout)
await handler()
@@ -358,7 +358,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
async def __handshake_security_send_result(self, allow: bool, allow_msg: str, deny_msg: str, deny_reason: str) -> None:
if allow:
- get_logger(0).info("[main] %s: %s", self._remote, allow_msg)
+ get_logger(0).info("%s [main]: %s", self._remote, allow_msg)
await self._write_struct("access OK", "L", 0)
else:
await self._write_struct("access denial flag", "L", 1, drain=(self.__rfb_version < 8))
@@ -425,9 +425,9 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
raise RfbError(f"Too many encodings: {encodings_count}")
self._encodings = RfbClientEncodings(frozenset(await self._read_struct("encodings list", "l" * encodings_count)))
- logger.info("[main] %s: Client features (SetEncodings):", self._remote)
+ logger.info("%s [main]: Client features (SetEncodings):", self._remote)
for item in self._encodings.get_summary():
- logger.info("[main] %s: ... %s", self._remote, item)
+ logger.info("%s [main]: ... %s", self._remote, item)
self.__check_encodings()
if self._encodings.has_ext_keys: # Preferred method
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index 3d460498..2f822ab9 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -157,14 +157,14 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
logger = get_logger(0)
await self.__stage1_authorized.wait_passed()
- logger.info("[kvmd] %s: Waiting for the SetEncodings message ...", self._remote)
+ logger.info("%s [kvmd]: Waiting for the SetEncodings message ...", self._remote)
if not (await self.__stage2_encodings_accepted.wait_passed(timeout=5)):
raise RfbError("No SetEncodings message recieved from the client in 5 secs")
assert self.__kvmd_session
try:
async with self.__kvmd_session.ws() as self.__kvmd_ws:
- logger.info("[kvmd] %s: Connected to KVMD websocket", self._remote)
+ logger.info("%s [kvmd]: Connected to KVMD websocket", self._remote)
self.__stage3_ws_connected.set_passed()
async for (event_type, event) in self.__kvmd_ws.communicate():
await self.__process_ws_event(event_type, event)
@@ -202,7 +202,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
streaming = False
async for frame in streamer.read_stream():
if not streaming:
- logger.info("[streamer] %s: Streaming ...", self._remote)
+ logger.info("%s [streamer]: Streaming ...", self._remote)
streaming = True
if frame["online"]:
await self.__queue_frame(frame)
@@ -211,9 +211,9 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
except StreamerError as err:
if isinstance(err, StreamerPermError):
streamer = self.__get_default_streamer()
- logger.info("[streamer] %s: Permanent error: %s; switching to %s ...", self._remote, err, streamer)
+ logger.info("%s [streamer]: Permanent error: %s; switching to %s ...", self._remote, err, streamer)
else:
- logger.info("[streamer] %s: Waiting for stream: %s", self._remote, err)
+ logger.info("%s [streamer]: Waiting for stream: %s", self._remote, err)
await self.__queue_frame("Waiting for stream ...")
await asyncio.sleep(1)
@@ -225,13 +225,13 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
streamer: Optional[BaseStreamerClient] = None
for streamer in self.__streamers:
if getattr(self._encodings, formats[streamer.get_format()]):
- get_logger(0).info("[streamer] %s: Using preferred %s", self._remote, streamer)
+ get_logger(0).info("%s [streamer]: Using preferred %s", self._remote, streamer)
return streamer
raise RuntimeError("No streamers found")
def __get_default_streamer(self) -> BaseStreamerClient:
streamer = self.__streamers[-1]
- get_logger(0).info("[streamer] %s: Using default %s", self._remote, streamer)
+ get_logger(0).info("%s [streamer]: Using default %s", self._remote, streamer)
return streamer
async def __queue_frame(self, frame: Union[Dict, str]) -> None:
@@ -382,14 +382,14 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
assert self.__stage1_authorized.is_passed()
assert self.__kvmd_session
logger = get_logger(0)
- logger.info("[main] %s: Printing %d characters ...", self._remote, len(text))
+ logger.info("%s [main]: Printing %d characters ...", self._remote, len(text))
try:
(keymap_name, available) = await self.__kvmd_session.hid.get_keymaps()
if self.__keymap_name in available:
keymap_name = self.__keymap_name
await self.__kvmd_session.hid.print(text, 0, keymap_name)
except Exception:
- logger.exception("[main] %s: Can't print characters", self._remote)
+ logger.exception("%s [main]: Can't print characters", self._remote)
async def _on_set_encodings(self) -> None:
assert self.__stage1_authorized.is_passed()
@@ -398,7 +398,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
has_quality = (await self.__kvmd_session.streamer.get_state())["features"]["quality"]
quality = (self._encodings.tight_jpeg_quality if has_quality else None)
- get_logger(0).info("[main] %s: Applying streamer params: jpeg_quality=%s; desired_fps=%d ...",
+ get_logger(0).info("%s [main]: Applying streamer params: jpeg_quality=%s; desired_fps=%d ...",
self._remote, quality, self.__desired_fps)
await self.__kvmd_session.streamer.set_params(quality, self.__desired_fps)
@@ -449,7 +449,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
logger = get_logger(0)
remote = rfb_format_remote(writer)
- logger.info("[entry] %s: Connected client", remote)
+ logger.info("%s [entry]: Connected client", remote)
try:
sock = writer.get_extra_info("socket")
if no_delay:
@@ -468,7 +468,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
async with kvmd.make_session("", "") as kvmd_session:
none_auth_only = await kvmd_session.auth.check()
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
- logger.error("[entry] %s: Can't check KVMD auth mode: %s", remote, tools.efmt(err))
+ logger.error("%s [entry]: Can't check KVMD auth mode: %s", remote, tools.efmt(err))
return
await _Client(
@@ -489,10 +489,10 @@ class VncServer: # pylint: disable=too-many-instance-attributes
shared_params=shared_params,
).run()
except Exception:
- logger.exception("[entry] %s: Unhandled exception in client task", remote)
+ logger.exception("%s [entry]: Unhandled exception in client task", remote)
finally:
if (await aiotools.close_writer(writer)):
- logger.info("[entry] %s: Connection is closed in an emergency", remote)
+ logger.info("%s [entry]: Connection is closed in an emergency", remote)
self.__handle_client = handle_client