Last active
July 10, 2024 15:36
-
-
Save sysraccoon/50673fdd6c654791b6884faa2bb07228 to your computer and use it in GitHub Desktop.
mitmproxy export event logs to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from mitmproxy.command import command | |
| from mitmproxy import types, ctx, log | |
| @command("custom_command.export_event_logs") | |
| def export_event_logs(filename: types.Path): | |
| export_logs = [] | |
| for log_entry in ctx.master.events.data: | |
| export_logs.append(log_entry_to_json(log_entry)) | |
| with open(filename, "w") as fp: | |
| fp.write(json.dumps(export_logs)) | |
| def log_entry_to_json(entry: log.LogEntry) -> dict: | |
| return { | |
| "message": entry.msg, | |
| "level": entry.level, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment