Set up basic logging. modified: listfix.py modified: listfix/__init__.py new file: listfix/log.py
Brian Barto bartobrian@gmail.com
Fri, 01 Apr 2022 15:40:34 -0400
3 files changed,
29 insertions(+),
1 deletions(-)
M
listfix.py
→
listfix.py
@@ -2,7 +2,11 @@ #!/usr/bin/python3
import sys import os -from listfix import Args, DB, Email, Errors +from listfix import Args, DB, Email, Errors, Log + +## Get log object + +log = Log() ## Set up the exception handler@@ -32,6 +36,9 @@ exit()
sender_email = email_in.get_sender_email() sender_name = email_in.get_sender_name() + log.info(f"Email from: {sender_email}") + log.info(f"Email list: {list_email}") + email_out = Email(email_in.get_content()) email_out.strip_headers(exclude = ["To", "Cc", "Subject", "Content-[^:]+", "MIME-Version"]) if (sender_email not in list_recipients):@@ -44,6 +51,7 @@ if sender_email in list_recipients:
list_recipients.remove(sender_email) for r in list_recipients: + log.info(f"Recipient: {r}") email_out.send(r) elif (command == "lists"):
M
listfix/__init__.py
→
listfix/__init__.py
@@ -3,3 +3,4 @@ from .db import DB
from .email import Email from .args import Args from .errors import Errors +from .log import Log
A
listfix/log.py
@@ -0,0 +1,19 @@
+class Log: + + def __init__(self): + self.log_file = open("/tmp/listfix_log.txt", "a") + + def info(self, txt): + txt = txt.rstrip() + self.log_file.write(f"[INFO] {txt}\n") + + def error(self, txt): + txt = txt.rstrip() + self.log_file.write(f"[ERROR] {txt}\n") + + def debug(self, txt): + txt = txt.rstrip() + self.log_file.write(f"[DEBUG] {txt}\n") + + def close(self): + self.log_file.close()