Skip to content

Commit

Permalink
feat(esp_rfc2217): Improved the logger message format
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-kocka committed Nov 12, 2024
1 parent 5569aa5 commit 39a12a4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions esp_rfc2217_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -120,7 +118,7 @@ def main():
try:
r.shortcircuit()
finally:
logging.info(" Disconnected")
logging.info("Disconnected")
r.stop()
client_socket.close()
ser.dtr = False
Expand All @@ -134,7 +132,7 @@ def main():
except socket.error as msg:
logging.error(str(msg))

logging.info(" --- exit ---")
logging.info("--- exit ---")


if __name__ == "__main__":
Expand Down

0 comments on commit 39a12a4

Please sign in to comment.