Created
August 7, 2014 17:00
-
-
Save binarytemple/5d0e02e845d1ee5988d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| """ | |
| Example usage: | |
| [~%]dategrep.py -s "2014-08-04 05:04:03.376" -e "2014-08-04 05:04:03.593" < ~/Downloads/riak@10.x.233.35-riak-debug/logs/platform_log_dir/console.log | |
| 2014-08-04 05:04:03.376 [info] <0.9440.850>@riak_repl_keylist_client:wait_for_fullsync:94 Full-sync with site "misc_foo_prod2" starting; 1 partitions. | |
| 2014-08-04 05:04:03.376 [info] <0.9440.850>@riak_repl_keylist_client:request_partition:121 Full-sync with site "misc_foo_prod2"; starting fullsync for 1141798154164767904846628775559596109106197299200 | |
| 2014-08-04 05:04:03.376 [info] <0.9440.850>@riak_repl_keylist_client:request_partition:127 Full-sync with site "misc_foo_prod2"; building keylist for 1141798154164767904846628775559596109106197299200, 0 remain | |
| 2014-08-04 05:04:03.587 [info] <0.9441.850>@riak_repl_fullsync_helper:handle_cast:307 Sorting keylist "/var/lib/riak/riak_repl/work/45095927/misc_foo_prod2-10.x.38.11:9080-10.x.38.23:53914/1141798154164767904846628775559596109106197299200.ours.sterm" | |
| """ | |
| import sys,time | |
| import optparse | |
| from datetime import date, datetime | |
| from dateutil import parser as dateparser | |
| now=datetime.utcnow().__str__() | |
| parser = optparse.OptionParser(version="%prog 1.0") | |
| parser.add_option('-s', '--start', action="store", | |
| dest="start", help="start time, for example: '2014-08-04 05:04:03.593'") | |
| parser.add_option('-e', '--end', action="store", | |
| dest="end", default=now , type="string", help="end time, for example: '2014-08-04 05:04:03.593'") | |
| options, args = parser.parse_args() | |
| if options.start == None: | |
| parser.error("No start time specified. For help, use -h") | |
| mask=datetime(1975, 1, 1, 0, 0) | |
| start = dateparser.parse(options.start,default=mask) | |
| end = dateparser.parse(options.end,default=mask) | |
| for line in sys.stdin: | |
| try: | |
| date = dateparser.parse( line.split("[")[0] ,default=datetime(1980, 1, 1, 0, 0)) | |
| # suit the <=, <, comparisons below to your needs: | |
| if start <= date < end: | |
| sys.stdout.write(line) | |
| except (ValueError, IndexError,TypeError): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment