TylerBrock / saw

Fast, multi-purpose tool for AWS CloudWatch Logs
MIT License
1.4k stars 77 forks source link

feat: add fuzzy searching for log group names #72

Open a-h opened 2 years ago

a-h commented 2 years ago

When you're building Lambda functions with CDK, you can't always guess the log prefix, and even if you can, it's a bit unweildy.

For example, with a CDK stack with logical ID "NodeCountExampleAwsLambdaStack" and a Lambda function called "CountGetFunction", CDK generates a CloudWatch Log Group of:

/aws/lambda/NodeCountExampleAwsLambda-CountGetFunctionD35D8410-

Note how "NodeCountExampleAwsLambdaStack" is truncated to "NodeCountExampleAwsLambda". There are also limits on the function logical ID.

To save me from having to use saw groups | grep CountGet, then copy / paste the outputted group name so that I can run saw get <groupname>, I thought it would be helpful to be able to "fuzzy search" the group name.

So in this PR, I've implemented a basic "contains substring" search for the log group that's only triggered when a --fuzzy flag is set.

You can get the logs directly with:

saw --fuzzy CountGet

Compared to:

saw get /aws/lambda/NodeCountExampleAwsLambda-CountGetFunctionD35D8410....

Obviously, it costs a CloudWatch Log API call or two if you use the fuzzy search flag, but it's not the default behaviour so won't affect anyone that doesn't use it.

TylerBrock commented 2 years ago

very nice -- I will take a look when I get some time to do so, thank you