lucagrulla / cw

The best way to tail AWS CloudWatch Logs from your terminal
https://www.lucagrulla.com/cw
Apache License 2.0
791 stars 59 forks source link

Convenience: Ability to fetch logs around a specified timestamp #219

Open Kantis opened 3 years ago

Kantis commented 3 years ago

Problem

It's frustrating to see surrounding events when you find something of interest in the log.

cw tail my-log-group -b7d | grep ERROR

> 2021-10-04T09:20:02,747 <ERROR> <45c352fb-63c8-473c-93f0-14d1cf34a879> ERROR for some reason

# Inconvenient part, constructing the surrounding timestamps
cw tail my-log-group --start="2021-10-04T09:19:00" --end="2021-10-04T09:21:00" 

Proposal

Provide an additional parameter -l, --relative-to="<Full DATE/DATETIME>" to the cw tail function, that can be used in conjunction to the relative parameters for -b, -e. Example:

cw tail my-log-group -l "2021-10-04T09:19:00" -b1m -e1m

Also it could be nice if -b and -e supported down to millisecond precision? Perhaps worthy of a separate ticket..

Alternatives

I considered whether the before/after should be merged into a single additional parameter, but I think it's more natural this way..

lucagrulla commented 2 years ago

Hi @Kantis Thank you for your suggestion. I can see what you want to achieve, and I believe you can achieve it with grep A and B options: i.e. cw tail my-log-group -b7d | grep ERROR -A 2 -B 2 will give you 2 lines before and after the grep hit.