From 39a12a43a26a2525ff47fbc2667344308593da73 Mon Sep 17 00:00:00 2001 From: Jakub Kocka Date: Tue, 12 Nov 2024 08:48:34 +0100 Subject: [PATCH] feat(esp_rfc2217): Improved the logger message format --- esp_rfc2217_server/__init__.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/esp_rfc2217_server/__init__.py b/esp_rfc2217_server/__init__.py index 7fe96625a..d4772ecb9 100644 --- a/esp_rfc2217_server/__init__.py +++ b/esp_rfc2217_server/__init__.py @@ -64,8 +64,7 @@ def main(): level = (logging.WARNING, logging.INFO, logging.DEBUG, logging.NOTSET)[ args.verbosity ] - logging.basicConfig(level=logging.INFO) - # logging.getLogger('root').setLevel(logging.INFO) + logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO) logging.getLogger("rfc2217").setLevel(level) # connect to serial port @@ -75,27 +74,26 @@ def main(): ser.dtr = False ser.rts = False - logging.info(" RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit") + logging.info("RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit") try: ser.open() except serial.SerialException as e: - logging.error(" Could not open serial port {}: {}".format(ser.name, e)) + logging.error(f"Could not open serial port {ser.name}: {e}") sys.exit(1) - logging.info(" Serving serial port: {}".format(ser.name)) + logging.info(f"Serving serial port: {ser.name}") settings = ser.get_settings() srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) srv.bind(("", args.localport)) srv.listen(1) - logging.info(f" TCP/IP port: {args.localport}") + logging.info(f"TCP/IP port: {args.localport}") host_ip = socket.gethostbyname(socket.gethostname()) - logging.info( - f"Waiting for connection ... use the 'rfc2217://{host_ip}:{args.localport}?ign_set_control' as a PORT" - ) + wait_msg = f"Waiting for connection ... use the 'rfc2217://{host_ip}:{args.localport}?ign_set_control' as a PORT" + logging.info(wait_msg) while True: srv.settimeout(5) @@ -111,7 +109,7 @@ def main(): logging.info("Exited with keyboard interrupt") break try: - logging.info(f" Connected by {addr[0]}:{addr[1]}") + logging.info(f"Connected by {addr[0]}:{addr[1]}") client_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) ser.rts = True ser.dtr = True @@ -120,7 +118,7 @@ def main(): try: r.shortcircuit() finally: - logging.info(" Disconnected") + logging.info("Disconnected") r.stop() client_socket.close() ser.dtr = False @@ -134,7 +132,7 @@ def main(): except socket.error as msg: logging.error(str(msg)) - logging.info(" --- exit ---") + logging.info("--- exit ---") if __name__ == "__main__":