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

Always fetch latest events in tail #215

Open
mkotsalainen opened this issue Sep 7, 2021 · 0 comments
Open

Always fetch latest events in tail #215

mkotsalainen opened this issue Sep 7, 2021 · 0 comments

Comments

@mkotsalainen
Copy link

Is your feature request related to a problem? Please describe.

I would like to always get the latest events from a certain log stream - like AWS CloudWatch console does it. If nothing recent has been published to a certain log - I would still want the latest n items to show up.

Describe the solution you'd like

If I tail a log with cw and there hasn't been a lot of traffic in that stream recently nothing will show. I could give it a --start parameter but I don't know what that start parameter should be. Some of logs are really high volume and some are almost empty.

By using aws logs get-log-events I get a timestamp of the latest log item, that could be used a indication of the start param.

Describe alternatives you've considered

I've been thinking of wrapping cw in a shell script that does this but I think this functionality would be better implemented in the util itself.

Additional context

I have a nice fuzzy finder logs setup that is almost complete - I just need this feature to ditch the AWS logs console altogether
:

declare -A log_streams

function refresh_log_streams_list {
  log_streams=()
}

function logs {
  # Mashup of https://github.com/lucagrulla/cw and https://github.com/junegunn/fzf
  # Also uses unbuffer avaiable on mac via brew install expect
  # Allows you to access logs quickly
  env=$1
  query=$2
  if [[ -z ${log_streams["$env"]} ]] ; then
    echo "refreshing $env log_stream_list"
    log_streams["$env"]=$(cw ls streams pilot-$env)
  fi
  echo "$log_streams["$env"]" | fzf --ansi --preview-window "right,80%" --info inline --border -q "$query" --preview-window follow --preview "unbuffer cw tail -tf pilot-$env:{}" | xargs -I '{}' cw tail -tf pilot-$env:{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants