From a659f2e49d6413e2285a4473b44d380e09ac543f Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 3 Jan 2021 19:27:24 +0100 Subject: [PATCH] Improved logging for emails Removed private data from debug export --- cps/config_sql.py | 2 +- cps/logger.py | 7 +++++++ cps/tasks/convert.py | 12 +++++++++--- cps/tasks/mail.py | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index b1e487f9..f7b300c0 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -275,7 +275,7 @@ class _ConfigSQL(object): def toDict(self): storage = {} for k, v in self.__dict__.items(): - if k[0] != '_' or k.endswith("password"): + if k[0] != '_' and not k.endswith("password") and not k.endswith("secret"): storage[k] = v return storage diff --git a/cps/logger.py b/cps/logger.py index a9606cb1..d2a41b71 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -49,6 +49,13 @@ class _Logger(logging.Logger): else: self.error(message, stacklevel=2, *args, **kwargs) + def debug_no_auth(self, message, *args, **kwargs): + if message.startswith("send: AUTH"): + self.debug(message[:16], stacklevel=2, *args, **kwargs) + else: + self.debug(message, stacklevel=2, *args, **kwargs) + + def get(name=None): return logging.getLogger(name) diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 75542b38..d3e74569 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -66,9 +66,15 @@ class TaskConvert(CalibreTask): # if we're sending to kindle after converting, create a one-off task and run it immediately # todo: figure out how to incorporate this into the progress try: - worker_thread.add(self.user, TaskEmail(self.settings['subject'], self.results["path"], - filename, self.settings, self.kindle_mail, - self.settings['subject'], self.settings['body'], internal=True)) + worker_thread.add(self.user, TaskEmail(self.settings['subject'], + self.results["path"], + filename, + self.settings, + self.kindle_mail, + self.settings['subject'], + self.settings['body'], + internal=True) + ) except Exception as e: return self._handleError(str(e)) diff --git a/cps/tasks/mail.py b/cps/tasks/mail.py index 8424f084..4f7ed777 100644 --- a/cps/tasks/mail.py +++ b/cps/tasks/mail.py @@ -44,7 +44,7 @@ class EmailBase: def send(self, strg): """Send `strg' to the server.""" - log.debug('send: %r', strg[:300]) + log.debug_no_auth('send: {}'.format(strg[:300])) if hasattr(self, 'sock') and self.sock: try: if self.transferSize: