0

The SAM CLI function to tail the logs is AWESOME. However, I find the formatting to be too verbose most of the time. The default formatting looks like this:

2021/12/13/[$LATEST]c87a125640ed4c66907f22c1d83ca63e 2021-12-13T13:11:09.388000 2021-12-13T13:11:09.388Z    1f99a541-76d7-494f-8f07-3f3e8397eedf    INFO    small change

but I want to have the option to just print out the message without the log stream and timestamp information so it just looks like this:

INFO    small change

Is there a way to pass in a formatting string for the log statements?

Brian
  • 1,675
  • 3
  • 19
  • 29

1 Answers1

0

You can use awk to only print the 5th and 6th column.

Try:

sam logs -n MyLambdaFunction --tail | awk '{print $5 " " $6}';

Demo:

output="2021/12/13/[$LATEST]c87a125640ed4c66907f22c1d83ca63e 2021-12-13T13:11:09.388000 2021-12-13T13:11:09.388Z    1f99a541-76d7-494f-8f07-3f3e8397eedf    INFO    small change";
echo $output | awk '{print $5 " " $6}';

Output:

INFO small
Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44