Skip to content

Instantly share code, notes, and snippets.

@athoune
Created May 17, 2014 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/06341225f10ad2fe1340 to your computer and use it in GitHub Desktop.
Save athoune/06341225f10ad2fe1340 to your computer and use it in GitHub Desktop.
Splitting large mongodb log with mtools.
#!/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