117 |
117 |
118 # the message, including possible tag/pid |
118 # the message, including possible tag/pid |
119 + r"(?P<message>(?P<tag>(?P<program>[^:\]]+)(?:\[(?P<pid>\d+)\])?: )?(?P<text>.*))\n?" |
119 + r"(?P<message>(?P<tag>(?P<program>[^:\]]+)(?:\[(?P<pid>\d+)\])?: )?(?P<text>.*))\n?" |
120 ) |
120 ) |
121 |
121 |
122 def __init__ (self, raw=False) : |
122 def __init__ (self, raw=False, facility=None) : |
123 """ |
123 """ |
124 Using given underlying line source. |
124 Using given underlying line source. |
125 """ |
125 """ |
126 |
126 |
127 self.raw = raw |
127 self.raw = raw |
|
128 self.facility = facility |
128 |
129 |
129 def parse_pri (self, match) : |
130 def parse_pri (self, match) : |
130 """ |
131 """ |
131 Parse pri/facility/severity. |
132 Parse pri/facility/severity. |
132 """ |
133 """ |
133 |
134 |
134 pri = match.group('pri') |
135 pri = match.group('pri') |
135 facility = match.group('facility') |
136 facility = match.group('facility') or self.facility |
136 severity = match.group('severity') |
137 severity = match.group('severity') |
137 |
138 |
138 if pri.isdigit() : |
139 if pri and pri.isdigit() : |
139 pri = int(pri) |
140 pri = int(pri) |
140 facility, severity = divmod(pri, 8) |
141 facility, severity = divmod(pri, 8) |
141 |
142 |
142 return dict( |
143 return dict( |
143 pri = pri, |
144 pri = pri, |
212 pid = match.group('pid'), |
210 pid = match.group('pid'), |
213 msg = match.group('text'), |
211 msg = match.group('text'), |
214 ) |
212 ) |
215 |
213 |
216 # facility/severity prefix? |
214 # facility/severity prefix? |
217 if match.group('pri') : |
215 item.update(self.parse_pri(match)) |
218 item.update(self.parse_pri(match)) |
|
219 |
216 |
220 return item |
217 return item |
221 |
218 |
222 def process (self, lines) : |
219 def process (self, lines) : |
223 """ |
220 """ |