Remove PosixPath() in logs and add proper exception logging

This commit is contained in:
Balakrishnan Balasubramanian 2023-06-22 00:49:23 -04:00
parent 1e6655a715
commit 2bf809c454
3 changed files with 10 additions and 10 deletions

View File

@ -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),

View File

@ -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))

View File

@ -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(