Remove private data from logs
This commit is contained in:
1 parent
b4fcd4c7bc
commit
52e651cf61
1 file changed
+9
-1
@@ -1,8 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
class CPLog():
|
class CPLog():
|
||||||
|
|
||||||
context = ''
|
context = ''
|
||||||
|
replace_private = ['api', 'apikey', 'api_key', 'password', 'username']
|
||||||
|
|
||||||
def __init__(self, context = ''):
|
def __init__(self, context = ''):
|
||||||
self.context = context
|
self.context = context
|
||||||
@@ -28,4 +30,10 @@ class CPLog():
|
|||||||
self.logger.critical(self.addContext(msg), exc_info = 1)
|
self.logger.critical(self.addContext(msg), exc_info = 1)
|
||||||
|
|
||||||
def addContext(self, msg):
|
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