MCPcopy Create free account
hub / github.com/logpai/logparser / parse

Method parse

logparser/Spell/Spell.py:250–307  ·  view source on GitHub ↗
(self, logname)

Source from the content-addressed store, hash-verified

248 self.printTree(node.childD[child], dep + 1)
249
250 def parse(self, logname):
251 starttime = datetime.now()
252 print("Parsing file: " + os.path.join(self.path, logname))
253 self.logname = logname
254 self.load_data()
255 rootNode = Node()
256 logCluL = []
257
258 count = 0
259 for idx, line in self.df_log.iterrows():
260 logID = line["LineId"]
261 logmessageL = list(
262 filter(
263 lambda x: x != "",
264 re.split(r"[\s=:,]", self.preprocess(line["Content"])),
265 )
266 )
267 constLogMessL = [w for w in logmessageL if w != "<*>"]
268
269 # Find an existing matched log cluster
270 matchCluster = self.PrefixTreeMatch(rootNode, constLogMessL, 0)
271
272 if matchCluster is None:
273 matchCluster = self.SimpleLoopMatch(logCluL, constLogMessL)
274
275 if matchCluster is None:
276 matchCluster = self.LCSMatch(logCluL, logmessageL)
277
278 # Match no existing log cluster
279 if matchCluster is None:
280 newCluster = LCSObject(logTemplate=logmessageL, logIDL=[logID])
281 logCluL.append(newCluster)
282 self.addSeqToPrefixTree(rootNode, newCluster)
283 # Add the new log message to the existing cluster
284 else:
285 newTemplate = self.getTemplate(
286 self.LCS(logmessageL, matchCluster.logTemplate),
287 matchCluster.logTemplate,
288 )
289 if " ".join(newTemplate) != " ".join(matchCluster.logTemplate):
290 self.removeSeqFromPrefixTree(rootNode, matchCluster)
291 matchCluster.logTemplate = newTemplate
292 self.addSeqToPrefixTree(rootNode, matchCluster)
293 if matchCluster:
294 matchCluster.logIDL.append(logID)
295 count += 1
296 if count % 1000 == 0 or count == len(self.df_log):
297 print(
298 "Processed {0:.1f}% of log lines.".format(
299 count * 100.0 / len(self.df_log)
300 )
301 )
302
303 if not os.path.exists(self.savePath):
304 os.makedirs(self.savePath)
305
306 self.outputResult(logCluL)
307 print("Parsing done. [Time taken: {!s}]".format(datetime.now() - starttime))

Callers 2

benchmark.pyFile · 0.45
demo.pyFile · 0.45

Calls 13

load_dataMethod · 0.95
preprocessMethod · 0.95
PrefixTreeMatchMethod · 0.95
SimpleLoopMatchMethod · 0.95
LCSMatchMethod · 0.95
addSeqToPrefixTreeMethod · 0.95
getTemplateMethod · 0.95
LCSMethod · 0.95
outputResultMethod · 0.95
LCSObjectClass · 0.85
formatMethod · 0.80

Tested by

no test coverage detected