I want to print some logs for debugging and testing, but existing logs are massive, so I want to print my own logs to stderr:
go run main.go 1>/dev/null
<
There are multiple methods to send a message to stderr
:
Creating a new log.Logger:
l := log.New(os.Stderr, "", 1)
l.Println("log message")
Using fmt.Fprintf:
fmt.Fprintf(os.Stderr, "log message: %s", str)
Directly writing to os.Stderr
using os.Stderr.WriteString:
os.Stderr.WriteString("log message")