mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 04:49:36 -07:00
Improve logger regex
This commit is contained in:
parent
1eb58ba864
commit
654ff7bdb6
1 changed files with 17 additions and 19 deletions
|
@ -121,17 +121,17 @@ class RegexFilter(logging.Filter):
|
||||||
"""
|
"""
|
||||||
Base class for regex log filter
|
Base class for regex log filter
|
||||||
"""
|
"""
|
||||||
|
REGEX = re.compile(r'')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(RegexFilter, self).__init__()
|
super(RegexFilter, self).__init__()
|
||||||
|
|
||||||
self.regex = re.compile(r'')
|
|
||||||
|
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
if not plexpy.CONFIG.LOG_BLACKLIST:
|
if not plexpy.CONFIG.LOG_BLACKLIST:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
matches = self.regex.findall(record.msg)
|
matches = self.REGEX.findall(record.msg)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
record.msg = self.replace(record.msg, match)
|
record.msg = self.replace(record.msg, match)
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ class RegexFilter(logging.Filter):
|
||||||
for arg in record.args:
|
for arg in record.args:
|
||||||
try:
|
try:
|
||||||
arg_str = str(arg)
|
arg_str = str(arg)
|
||||||
matches = self.regex.findall(arg_str)
|
matches = self.REGEX.findall(arg_str)
|
||||||
if matches:
|
if matches:
|
||||||
for match in matches:
|
for match in matches:
|
||||||
arg_str = self.replace(arg_str, match)
|
arg_str = self.replace(arg_str, match)
|
||||||
|
@ -161,11 +161,11 @@ class PublicIPFilter(RegexFilter):
|
||||||
"""
|
"""
|
||||||
Log filter for public IP addresses
|
Log filter for public IP addresses
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
REGEX = re.compile(
|
||||||
super(PublicIPFilter, self).__init__()
|
r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.-]){3}'
|
||||||
|
r'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
|
||||||
# Currently only checking for ipv4 addresses
|
r'(?!\d*-[a-z0-9]{6})'
|
||||||
self.regex = re.compile(r'[0-9]+(?:[.-][0-9]+){3}(?!\d*-[a-z0-9]{6})')
|
)
|
||||||
|
|
||||||
def replace(self, text, ip):
|
def replace(self, text, ip):
|
||||||
if helpers.is_public_ip(ip.replace('-', '.')):
|
if helpers.is_public_ip(ip.replace('-', '.')):
|
||||||
|
@ -178,12 +178,11 @@ class EmailFilter(RegexFilter):
|
||||||
"""
|
"""
|
||||||
Log filter for email addresses
|
Log filter for email addresses
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
REGEX = re.compile(
|
||||||
super(EmailFilter, self).__init__()
|
r'([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@'
|
||||||
|
r'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)',
|
||||||
self.regex = re.compile(r'([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@'
|
re.IGNORECASE
|
||||||
r'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)',
|
)
|
||||||
re.IGNORECASE)
|
|
||||||
|
|
||||||
def replace(self, text, email):
|
def replace(self, text, email):
|
||||||
email_parts = email.partition('@')
|
email_parts = email.partition('@')
|
||||||
|
@ -194,10 +193,9 @@ class PlexTokenFilter(RegexFilter):
|
||||||
"""
|
"""
|
||||||
Log filter for X-Plex-Token
|
Log filter for X-Plex-Token
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
REGEX = re.compile(
|
||||||
super(PlexTokenFilter, self).__init__()
|
r'X-Plex-Token(?:=|%3D)([a-zA-Z0-9\-_]+)'
|
||||||
|
)
|
||||||
self.regex = re.compile(r'X-Plex-Token(?:=|%3D)([a-zA-Z0-9]+)')
|
|
||||||
|
|
||||||
def replace(self, text, token):
|
def replace(self, text, token):
|
||||||
return text.replace(token, 16 * '*')
|
return text.replace(token, 16 * '*')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue