dimanche 24 juillet 2016

How can I parse a log file to JSON

I have a log file (called preprocstats.log) and i would like to know how parse it to a JSON format file using Python 2.6.

The input of the log file is:

Preprocessor Profile Statistics (all)
==========================================================
Num            Preprocessor Layer     Checks      Exits  
===            ============ =====     ======      =====  
 1              httpinspect     0          1          1  
 2                   detect     0         33         33   
... (and more rows)

And i want to parse it to JSON, for example with this output:

{"Num": 1, "Preprocessor": "httpinspect", "Layer": 0, "Checks": 1,   "Exits": 1}
{"Num": 2, "Preprocessor": "detect", "Layer": 0, "Checks": 33, "Exits": 33}
... (and the rest of rows)

Aucun commentaire:

Enregistrer un commentaire