Coverage for /usr/local/lib/python3.10/site-packages/opal_common-0.0.0-py3.10.egg/opal_common/logging_utils/filter.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 11:54 +0000

1from typing import List 

2 

3 

4class ModuleFilter: 

5 """Filter logs by module name.""" 

6 

7 def __init__( 

8 self, exclude_list: List[str] = None, include_list: List[str] = None 

9 ) -> None: 

10 """[summary] 

11 

12 Args: 

13 exclude_list (List[str], optional): module name (prefixes) to reject. Defaults to []. 

14 include_list (List[str], optional): module name (prefixes) to include (even if higher form is excluded). Defaults to []. 

15 

16 Usage: 

17 ModuleFilter(["uvicorn"]) # exclude all logs coming from module name starting with "uvicorn" 

18 ModuleFilter(["uvicorn"], ["uvicorn.access]) # exclude all logs coming from module name starting with "uvicorn" except ones starting with "uvicorn.access") 

19 """ 

20 self._exclude_list = exclude_list or [] 

21 self._include_list = include_list or [] 

22 

23 def filter(self, record): 

24 name: str = record["name"] 

25 for module in self._include_list: 

26 if name.startswith(module): 

27 return True 

28 for module in self._exclude_list: 

29 if name.startswith(module): 

30 return False 

31 return True