Skip to content

Instantly share code, notes, and snippets.

@you06
Last active March 24, 2020 17:12
Show Gist options
  • Save you06/e10d8ce5480f933c3de5e34d1b18658f to your computer and use it in GitHub Desktop.
Save you06/e10d8ce5480f933c3de5e34d1b18658f to your computer and use it in GitHub Desktop.
Parse log for pocket, seperate them into files.
#!/usr/bin/python
import sys, re, os
from time import gmtime, strftime
if __name__ == '__main__':
writers = {}
dirname = strftime("log-%Y-%m-%d-%H:%M:%S", gmtime())
os.mkdir(dirname)
for line in sys.stdin:
m = re.search('\[((conn|abtest).*?)\](.*)$', line)
file = 'main'
content = line
if m:
file = m.group(1)
content = m.group(3).strip()
if not file in writers:
print('open ' + file)
writers[file] = open(os.path.join(dirname, file + '.log'), 'a')
if content != '':
writers[file].write(content)
writers[file].write('\n')
for writer in writers.values():
writer.close()
print('log parse to %s' % dirname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment