Remove private data from logs
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user