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

Expand \n and \t please! #216

Open mattes3 opened 3 years ago

mattes3 commented 3 years ago

Is your feature request related to a problem? Please describe. I have difficulties to read my logs that are in JSON format. This is a sample log message, it is structured like this:

{"timestamp":"2021-09-07T08:24:40.062Z","level":"INFO","thread":"qtp1533672820-41","logger":"com.gettheaudience.somepackage.UserAppService","message":"BIZEVENT: Subscription 154 updated, new status = PAYING","context":"default"}

To read these messages, I do this:

cw tail -b2h -f -s -t -l -q '[thread, message]' my-log-group-name

This works fine.

Now the frustration comes when I read a log where the "message" field contains new-line \n and tab characters \t, typically exception stack traces generated by Java. On screen, they look like a big bunch of garbled characters because the new-line \n does not cause a line break in cw.

Describe the solution you'd like

I would like that cw gets an option that tells it to replace \n by a real line break, and \t by some number of spaces. This would make my log perfectly readable. It would be a bonus if cw used the entire rules for JSON, e.g. \" should be replaced by ", and so on.

Describe alternatives you've considered

I briefly considered using "jq" with "raw" output for this. However, jq is confused by the other fields in the output from cw, as jq does not know that there is valid JSON later in the line.

lucagrulla commented 3 years ago

Hi, thank you for the feature request. This is not a top priority right now, but I would happily review a good Pull Request for merging into main.