Skip to content

Commit

Permalink
匿名化日志中的用户名
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuukiy committed Nov 19, 2023
1 parent 2175965 commit ae59dfe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class DetailedFormatter(logging.Formatter):
def __init__(self, fmt='%(asctime)s %(name)s:%(lineno)d %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', *args) -> None:
super().__init__(fmt, datefmt, *args)
username = os.getlogin()
self.anonymize = re.compile(r'([\\/]*)' + username + '([\\/]*)', flags=re.I)

def format(self, record):
raw = super().format(record)
s = self.anonymize.sub(r'\1javsp\2', raw)
return s

def formatException(self, ei):
s = super().formatException(ei)
# ei[1] 是异常的实例,从中提取除了异常的message外的其他参数
Expand Down

0 comments on commit ae59dfe

Please sign in to comment.