Skip to content

Commit

Permalink
Renaming variables and changing config parameter to [warning_filters]
Browse files Browse the repository at this point in the history
  • Loading branch information
pvnbhargava committed Jan 7, 2020
1 parent 677f73f commit 7ebca75
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions BPG/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup_logger(log_path: str,
# Add filter to prevent dataprep debug logs from hitting the main logger

# Add filter to prevent duplicates of annoying messages
duplicate_filter = DontRepeatFilter()
duplicate_filter = WarningFilter()
out_handler.addFilter(duplicate_filter)

# Print out the current date and time
Expand Down Expand Up @@ -143,16 +143,16 @@ def callback():
duplicate_filter.clear_history()


class DontRepeatFilter(logging.Filter):
class WarningFilter(logging.Filter):
def __init__(self):
logging.Filter.__init__(self, 'DontRepeatFilter')
excludes = BPG.run_settings['bpg_config'].get('duplicate_filter_excludes', [])
self.dont_repeat_filters = dict()
for pattern in excludes:
self.dont_repeat_filters[pattern] = 0
logging.Filter.__init__(self, 'WarningFilter')
filters = BPG.run_settings['bpg_config'].get('warning_filters', [])
self.filter_dict = dict()
for pattern in filters:
self.filter_dict[pattern] = 0

# Make a regex that matches if any of our regexes match.
self.combined_regex = "(" + ")|(".join(excludes) + ")"
self.combined_regex = "(" + ")|(".join(filters) + ")"

def filter(self, record):
if not re.match(self.combined_regex, record.msg):
Expand All @@ -167,8 +167,8 @@ def filter(self, record):
# return False

def clear_history(self):
for key in self.dont_repeat_filters:
self.dont_repeat_filters[key] = 0
for key in self.filter_dict:
self.filter_dict[key] = 0

def add_key(self, key):
self.dont_repeat_filters[key] = 0
self.filter_dict[key] = 0

0 comments on commit 7ebca75

Please sign in to comment.