I want to print some logs for debugging and testing, but previous logs are massive, So I should print my own logs to stderr:
go run main.go 1>/dev/null
So that I can just see my own logs.
What should I do?
Thank you
The log
package by default prints to os.Stderr
.
You can also use os.Stderr
directly (it's an os.File
).
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")