Remove private data from logs

This commit is contained in:
Ruud
2011-08-30 23:27:57 +02:00
parent b4fcd4c7bc
commit 52e651cf61
+9 -1
View File
@@ -1,8 +1,10 @@
import logging
import re
class CPLog():
context = ''
replace_private = ['api', 'apikey', 'api_key', 'password', 'username']
def __init__(self, context = ''):
self.context = context
@@ -28,4 +30,10 @@ class CPLog():
self.logger.critical(self.addContext(msg), exc_info = 1)
def addContext(self, msg):
return '[%+25.25s] %s' % (self.context[-25:], msg)
return '[%+25.25s] %s' % (self.context[-25:], self.removePrivateData(msg))
def removePrivateData(self, msg):
for replace in self.replace_private:
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)
return msg