diff options
author | Roald de Vries <rdevries@thoughtworks.com> | 2016-09-28 14:05:25 -0300 |
---|---|---|
committer | Roald de Vries <rdevries@thoughtworks.com> | 2016-09-28 14:05:25 -0300 |
commit | 15e6127a58a7441d2170a4426da9b7a3e2e7b5d1 (patch) | |
tree | 7d79dacb5f1d6716f95bdd11d9d725cb4a1a1e99 /service/pixelated/config | |
parent | 37366d260344955bd422e996a57c2052ac3ef57c (diff) |
remove private key from [gnupg] logs the right way
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() |