diff options
Diffstat (limited to 'service/pixelated/config')
-rw-r--r-- | service/pixelated/config/logger.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/service/pixelated/config/logger.py b/service/pixelated/config/logger.py index a8000926..e28ceddd 100644 --- a/service/pixelated/config/logger.py +++ b/service/pixelated/config/logger.py @@ -19,19 +19,24 @@ import os from twisted.python import log +class PrivateKeyFilter(logging.Filter): + + def filter(self, record): + if '-----BEGIN PGP PRIVATE KEY BLOCK-----' in record.msg: + record.msg = '*** private key removed by %s.%s ***' % (type(self).__module__, type(self).__name__) + return True + + def init(debug=False): debug_enabled = debug or os.environ.get('DEBUG', False) - logging_level = logging.DEBUG if debug_enabled else logging.WARN - log_format = "%(asctime)s [%(name)s] %(levelname)s %(message)s" - date_format = '%Y-%m-%d %H:%M:%S' + logging_level = logging.DEBUG if debug_enabled else logging.INFO logging.basicConfig(level=logging_level, - format=log_format, - datefmt=date_format, + format='%(asctime)s [%(name)s] %(levelname)s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', filemode='a') + logging.getLogger('gnupg').addFilter(PrivateKeyFilter()) + observer = log.PythonLoggingObserver() - # don't remove this line, it fix the PGP private key logged - logging.getLogger('gnupg').setLevel(logging.WARN) - logging.getLogger('pixelated').setLevel(logging.INFO) observer.start() |