Created
December 10, 2011 01:31
-
-
Save msabramo/1454197 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 | |
| import re | |
| import sys | |
| phperrors = file('phperrors') | |
| applog_files = {} | |
| def copy_line_to_applog(line, hour): | |
| if not hour in applog_files: | |
| applog_files[hour] = file('test/applog.%s' % hour, 'a') | |
| applog_files[hour].write(line) | |
| def process_session_log_line(line): | |
| # Sample line: | |
| # Dec 9 17:13:05 web01.dev.cloud.cheggnet.com chegglib[19393]... | |
| match = re.match('(?P<month>[A-Z][a-z][a-z]) {1,2}(?P<day_of_month>\d+) (?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+) web', line) | |
| if match: | |
| hour = match.groupdict()['hour'] | |
| copy_line_to_applog(line, hour) | |
| for line in phperrors.readlines(): | |
| if 'SESSION_LOG' in line: | |
| process_session_log_line(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment