-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #667 from HubSpot/logfetch_cache
add logsearch and use-cache option for live logs
- Loading branch information
Showing
5 changed files
with
201 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import re | ||
import sys | ||
import fnmatch | ||
import logfetch_base | ||
from termcolor import colored | ||
|
||
def find_cached_logs(args): | ||
matching_logs = [] | ||
log_fn_match = get_matcher(args) | ||
for filename in os.listdir(args.dest): | ||
if fnmatch.fnmatch(filename, log_fn_match) and in_date_range(args, filename): | ||
if args.verbose: | ||
sys.stderr.write(colored('Including log {0}\n'.format(filename), 'magenta')) | ||
matching_logs.append('{0}/{1}'.format(args.dest, filename)) | ||
else: | ||
if args.verbose: | ||
sys.stderr.write(colored('Excluding log {0}, not in date range\n'.format(filename), 'magenta')) | ||
return matching_logs | ||
|
||
|
||
def in_date_range(args, filename): | ||
timestamps = re.findall(r"\d{13}", filename) | ||
if timestamps: | ||
return logfetch_base.is_in_date_range(args, int(str(timestamps[-1])[0:-3])) | ||
else: | ||
return True | ||
|
||
def get_matcher(args): | ||
if args.taskId: | ||
if 'filename' in args.file_pattern and args.logtype: | ||
return '{0}*{1}*'.format(args.taskId, args.logtype) | ||
else: | ||
return '{0}*'.format(args.taskId) | ||
elif args.deployId and args.requestId: | ||
if 'filename' in args.file_pattern and args.logtype: | ||
return '{0}-{1}*{2}*'.format(args.requestId, args.deployId, args.logtype) | ||
else: | ||
return '{0}-{1}*'.format(args.requestId, args.deployId) | ||
else: | ||
if 'filename' in args.file_pattern and args.logtype: | ||
return '{0}*{1}*'.format(args.requestId, args.logtype) | ||
else: | ||
return '{0}*'.format(args.requestId) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
setup( | ||
name='singularity-logfetch', | ||
version='0.19.0', | ||
version='0.20.0', | ||
description='Singularity log fetching and searching', | ||
author="HubSpot", | ||
author_email='[email protected]', | ||
|
@@ -24,7 +24,8 @@ | |
'console_scripts':[ | ||
'logfetch=logfetch.entrypoint:fetch', | ||
'logtail=logfetch.entrypoint:tail', | ||
'logcat=logfetch.entrypoint:cat' | ||
'logcat=logfetch.entrypoint:cat', | ||
'logsearch=logfetch.entrypoint:search' | ||
], | ||
} | ||
) |