Last active
March 24, 2020 17:12
-
-
Save you06/e10d8ce5480f933c3de5e34d1b18658f to your computer and use it in GitHub Desktop.
Parse log for pocket, seperate them into files.
This file contains 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
#!/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