Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean goreplay logfile
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Cleans a https://goreplay.org/ log file of any requests containing the provided string.
Usage: python clean-goreplay-logfile.py {PATH_TO_LOGFILE} {CLEAN_STRING}
"""
import sys
import os
import codecs
import StringIO
def main():
if len(sys.argv) != 3:
print("Supply a source file and clean string as arguments")
sys.exit(1)
source_file = os.path.abspath(sys.argv[1])
output_file = source_file + '.cleaned'
clean_string = sys.argv[2]
babeuffer = StringIO.StringIO() # https://upload.wikimedia.org/wikipedia/commons/b/b9/Fran%C3%A7ois-No%C3%ABl_Babeuf.jpg
for line in codecs.open(source_file, 'r', 'utf-8'):
if u'🐵🙈🙉' in line:
# flush le babeuffer
if clean_string not in babeuffer.getvalue():
with codecs.open(output_file, 'a', 'utf-8') as f:
f.write(babeuffer.getvalue())
babeuffer.close()
babeuffer = StringIO.StringIO()
babeuffer.write(line)
# flush le babeuffer one last time
if clean_string not in babeuffer.getvalue():
with codecs.open(output_file, 'a', 'utf-8') as f:
f.write(babeuffer.getvalue())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment