logging_filters.py
Go to the documentation of this file.
00001 import logging
00002 
00003 class IgnoreIfContainsFilter(logging.Filter):
00004     """
00005     Filter out messages that contain a certain string.
00006 
00007     If a message contains any of the substrings in 'params', the message
00008     will get filtered.
00009 
00010     To add to the config as a filter called "ignore_status",
00011     "filters" : {
00012         "ignore_status": {
00013             "()" : "nasa_common_logging.IgnoreIfContainsFilter",
00014             "params" : ["name:status","state:\"COMPLETE\"", "args=(), kwargs={}", "callback"]
00015         }
00016     }
00017     """
00018 
00019     def __init__(self, params=[]):
00020         """
00021         @type params list
00022         @param params List of strings to search for filtering
00023         """
00024         self.params = params
00025 
00026     def filter(self, record):
00027         allow = True
00028         for param in self.params:
00029             if str(param) in str(record.msg):
00030                 allow = False
00031 
00032         return allow


nasa_common_logging
Author(s):
autogenerated on Sun Feb 3 2019 03:42:09