mercredi 7 janvier 2015

Best practices to parse a log file using Python


I'm writing a Python tool to parse a log file from game server. The log file is of format:



ms:classname::id::method::arg1::arg2....


There are a lot of classes, and a lot of methods for each class, and each of them has its own format (number and meaning of arguments). I want to reconstruct the game (or at least relevant parts of it) from the log. I thought about doing something like this:



  • Creating a .format file where the formats of all the files are listed.

  • Each time I'll read the log, I'll analyze the format file, and create a dictionary of dictionaries - each class will have its own dictionary of methods, and the dictionary of each method would contain the args as a list. Then, each time I read a line, I'll check the dictionary for the format of the needed method of the needed class, and parse the line accordingly, and create some field-value dictionary structure to contain the information.


This seems reasonable, but I don't want to reinvent the wheel - I'm sure someone have thought about this already... Any smarter way to do it? Any shortcuts that could save me some work?





Aucun commentaire:

Enregistrer un commentaire