jorgebastida / awslogs

AWS CloudWatch logs for Humans™
Other
4.86k stars 336 forks source link

Log streams with square brackets cannot be used #392

Open justin8 opened 1 year ago

justin8 commented 1 year ago

When calling awslogs get with a log stream that contains square brackets ([ ]) I get the following error:

Traceback (most recent call last):
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/site-packages/awslogs/bin.py", line 179, in main
    getattr(logs, options.func)()
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/site-packages/awslogs/core.py", line 109, in list_logs
    streams = list(self._get_streams_from_pattern(self.log_group_name, self.log_stream_name))
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/site-packages/awslogs/core.py", line 101, in _get_streams_from_pattern
    reg = re.compile('^{0}'.format(pattern))
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/jdray/.pyenv/versions/3.8.12/lib/python3.8/sre_parse.py", line 549, in _parse
    raise source.error("unterminated character set",
re.error: unterminated character set at position 12

Repro steps: awslogs get my/log/stream "2023/06/01/[$LATEST]37fc8397fa59492cab1e6de1ad5d3e1f"

NewbiZ commented 2 weeks ago

My understanding is that the log streams you provide are actually regular expressions. Most of the time is doesn't matter, as one very rarely uses regular expression symbols as log stream names ([]()*. etc).

In your case it does matter though, but it's easily fixed by escaping your log stream name just as you would a regular expression: awslogs get my/log/stream "2023/06/01/\[$LATEST\]37fc8397fa59492cab1e6de1ad5d3e1f"