4f498848327dcc545921e964a9863cdff11079f9
[logging-analytics.git] / pylog / onaplogging / marker / markerFilter.py
1 # Copyright 2018 ke liang <lokyse@163.com>.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import sys
16 from logging import Filter
17 from .marker import matchMarkerHelp
18
19
20 class MarkerFilter(Filter):
21
22     def __init__(self, name="", markers=None):
23         if sys.version_info > (2, 7):
24             super(MarkerFilter, self).__init__(name)
25         else:
26             Filter.__init__(self, name)
27
28         self.markerToMatch = markers
29
30     def filter(self, record):
31         # compare filter's markers with record's marker
32         return matchMarkerHelp(record, self.markerToMatch)