Created
May 17, 2014 13:04
-
-
Save athoune/06341225f10ad2fe1340 to your computer and use it in GitHub Desktop.
Splitting large mongodb log with mtools.
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/env python | |
import sys | |
from mtools.util.logfile import LogFile | |
log = LogFile(open(sys.argv[1], 'r')) | |
day = None | |
out = None | |
for line in log: | |
d = line.datetime | |
if d is None: | |
continue | |
if day != (d.year, d.month, d.day): | |
day = (d.year, d.month, d.day) | |
print d | |
if out is not None: | |
out.close() | |
out = open(d.strftime('mongo-%y-%m-%d.log'), 'w') | |
out.write(line.get_line_str()) | |
out.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment