Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding command line argument to disable listing of all log streams #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions awslogs/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def add_date_range_arguments(parser, default_start='5m'):
dest="query",
help="JMESPath query to use in filtering the response data")

get_parser.add_argument("--exact-stream",
action='store_true',
dest='exact_stream_enabled',
help="Stream argument is exact match. Do not list all streams")

# groups
groups_parser = subparsers.add_parser('groups', description='List groups')
groups_parser.set_defaults(func="list_groups")
Expand Down
9 changes: 8 additions & 1 deletion awslogs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self, **kwargs):
self.output_timestamp_enabled = kwargs.get('output_timestamp_enabled')
self.output_ingestion_time_enabled = kwargs.get(
'output_ingestion_time_enabled')
self.exact_stream_enabled = kwargs.get('exact_stream_enabled')
self.start = self.parse_datetime(kwargs.get('start'))
self.end = self.parse_datetime(kwargs.get('end'))
self.query = kwargs.get('query')
Expand All @@ -103,10 +104,16 @@ def _get_streams_from_pattern(self, group, pattern):
if re.match(reg, stream):
yield stream

def _get_streams(self, group, pattern):
if self.exact_stream_enabled:
return list([pattern])
else:
return list(self._get_streams_from_pattern(self.log_group_name, self.log_stream_name))

def list_logs(self):
streams = []
if self.log_stream_name != self.ALL_WILDCARD:
streams = list(self._get_streams_from_pattern(self.log_group_name, self.log_stream_name))
streams = self._get_streams(self.log_group_name, self.log_stream_name)
if len(streams) > self.FILTER_LOG_EVENTS_STREAMS_LIMIT:
raise exceptions.TooManyStreamsFilteredError(
self.log_stream_name,
Expand Down