Ich habe eine große Protokolldatei mit großem Volumen. Wie nehme ich nur die JSON-Zeichenkette, nur die JSON-Zeichenkette nur, wenn es einen Fehler in der nächsten Zeile gibt, aber nach '_____GP D_____' in der vorherigen Zeile?Python analysieren von Protokolldatei
2017-04-22T11:27:11+06:00 smth.com pgp: [16136]: INFO:modules.gp.helpers.parameter_getter:_____GP D_____
2017-04-22T11:27:11+06:00 smth.com pgp: [16136]: {'D': 't12', 'telephone': None, 'from_time': '2016-04-22 11:30', 'C': 'C12', 'to_time': '2016-04-22 11:40', 'email': None}
2017-04-22T11:27:11+06:00 smth.com pgp: [16136]: INFO:tornado.access:200 POST /gp/C (192.168.1.240) 15.77ms
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: INFO:modules.security.authentication:LOADING USER...
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: INFO:modules.gp.helpers.parameter_getter:_____GP D_____
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: {'D': 'testim12', 'telephone': None, 'from_time': '2017-04-20 17:30', 'C': 'CnGP13', 'to_time': '2017-04-22 21:40', 'email': None}
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: ERROR:modules.common.actionexception:ActionError: [{'from': 'time is already passed'}]
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: Traceback (most recent call last):
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: File "/app/src/modules/base/actions/base_action.py", line 96, in do_action
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: self._produce_response()
2017-04-22T11:28:19+06:00 smth.com pgp: [16136]: modules.common.actionexception.ActionValidationErr: []
zum Beispiel aus dieser Protokolldatei möchte ich
'{' D ': 'testim12', 'Telefon': Keine, 'FROM_TIME': '2017.04.20 17.30', 'C': 'CnGP13', 'to_time': '2017-04-22 21:40', 'E-Mail': Keine} '.
Nur wenn ich eine Ausnahme habe, 'FEHLER: modules.common.actionexception: ActionError:' in der nächsten Zeile? wie mache ich es?
Sie müssen keine Regex dafür verwenden: Lesen Sie das Protokoll für Zeile, verwenden Sie eine begrenzte Aufteilung und überprüfen Sie die 5. Spalte. –
Warum das Regex-Tag entfernen? Jetzt kann ich nicht zurück ... – sln