kaitian521 kaitian521 - 21 days ago 6
Linux Question

How to print message to stderr in Go?

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

Answer

The log package by default prints to os.Stderr.

You can also use os.Stderr directly (it's an os.File).