This is code that converts the entered value to JSON format. It shows the correct output but I want to store that output and return it using fmt.Printf
package main
import (
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&log.JSONFormatter{})
standardFields := log.Fields{
"Number of threads": "1",
"Odd number": "3",
}
log.WithFields(standardFields).Info("Golang")
}
When you create a new logger with logrus.New(), you can provide the
Outfield to point to anyio.Writeryou wish. Here's the documentation for this field:So, for example you could create a new bytes.Buffer and set that as the
Outfield. This is akin to "logging to a variable".Similarly, you can set the output of the default logger with the SetOutput function.