From 2bf809c454bc9ea49b75f6e085f1a91414f4abec Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Thu, 22 Jun 2023 00:49:23 -0400 Subject: [PATCH] Remove PosixPath() in logs and add proper exception logging --- mail4one/pop3.py | 6 +++--- mail4one/server.py | 2 +- mail4one/smtp.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mail4one/pop3.py b/mail4one/pop3.py index e514fe9..8e5c25d 100644 --- a/mail4one/pop3.py +++ b/mail4one/pop3.py @@ -321,8 +321,8 @@ async def start_session() -> None: except ClientError as c: write(err("Something went wrong")) logger.error(f"Unexpected client error: {c}") - except Exception as e: - logger.error(f"Serious client error: {e}") + except: + logger.exception("Serious client error") raise finally: with contextlib.suppress(KeyError): @@ -371,7 +371,7 @@ async def create_pop_server( timeout_seconds: int = 60, ) -> asyncio.Server: logging.info( - f"Starting POP3 server {host=}, {port=}, {mails_path=}, {len(users)=}, {ssl_context != None=}, {timeout_seconds=}" + f"Starting POP3 server {host=}, {port=}, {mails_path=!s}, {len(users)=}, {ssl_context != None=}, {timeout_seconds=}" ) return await asyncio.start_server( make_pop_server_callback(mails_path, users, timeout_seconds), diff --git a/mail4one/server.py b/mail4one/server.py index 3a400b5..efdac58 100644 --- a/mail4one/server.py +++ b/mail4one/server.py @@ -150,7 +150,7 @@ def main() -> None: else: cfg = config.Config(args.config.read_text()) setup_logging(config.LogCfg(cfg.logging)) - logging.info(f"Starting mail4one {args.config=}") + logging.info(f"Starting mail4one {args.config=!s}") asyncio.run(a_main(cfg)) diff --git a/mail4one/smtp.py b/mail4one/smtp.py index a6cb3af..6f9ae3e 100644 --- a/mail4one/smtp.py +++ b/mail4one/smtp.py @@ -75,8 +75,8 @@ def protocol_factory_starttls(mails_path: Path, tls_context=context, enable_SMTPUTF8=True, ) - except Exception as e: - logger.error("Something went wrong", e) + except: + logger.exception("Something went wrong") raise return smtp @@ -87,8 +87,8 @@ def protocol_factory(mails_path: Path, mbox_finder: Callable[[str], try: handler = MyHandler(mails_path, mbox_finder) smtp = SMTP(handler=handler, enable_SMTPUTF8=True) - except Exception as e: - logger.error("Something went wrong", e) + except: + logger.exception("Something went wrong") raise return smtp @@ -101,7 +101,7 @@ async def create_smtp_server_starttls( ssl_context: ssl.SSLContext, ) -> asyncio.Server: logging.info( - f"Starting SMTP STARTTLS server {host=}, {port=}, {mails_path=}, {ssl_context != None=}" + f"Starting SMTP STARTTLS server {host=}, {port=}, {mails_path=!s}, {ssl_context != None=}" ) loop = asyncio.get_event_loop() return await loop.create_server( @@ -121,7 +121,7 @@ async def create_smtp_server( ssl_context: ssl.SSLContext | None = None, ) -> asyncio.Server: logging.info( - f"Starting SMTP server {host=}, {port=}, {mails_path=}, {ssl_context != None=}" + f"Starting SMTP server {host=}, {port=}, {mails_path=!s}, {ssl_context != None=}" ) loop = asyncio.get_event_loop() return await loop.create_server(