Golang vesion: 1.18.3
Logging libs used:
"log"
"github.com/kdar/logrus-cloudwatchlogs"
"github.com/sirupsen/logrus"
I'm writing a AWS Lambda using Go. It sits behind an AWS APIGateway as a REST API. I'm trying to log the requests got into it and the responses it sends back. Let's say the example request payload is:
const jsonData = `{"name": "Yomiko","address": {"city": "Tokyo","street": "Shibaura St"},"children":[{"lastName": "Takayashi"}],"isEmployed": false}`
When I log it using standard "log" library as below,
log.Println("JSON Data: ", jsonData)
It's printed nicely in the targeted CloudWatch Stream maintaining the JSON format as below,
Image 1: CloudWatch log with standard "log" library
However, when I used logrus with logrus-cloudwatchlogs as below,
hook, err := logrus_cloudwatchlogs.NewHook(transactionLogGroup, transactionLogStream, sess)
l := logrus.New()
l.Hooks.Add(hook)
l.Out = ioutil.Discard
l.Formatter = &logrus.JSONFormatter{}
l.Println("JSON Data: ", jsonData)
It adds backslashes as shown below and loses the nice JSON Format,
Image 2: CloudWatch log with "logrus" library
My question for you good people is,
How can I persevere the nice JSON format as shown in Image 1 when I use the "logrus" library? Please note that using standard "log" library is not an option here.