Reputation: 6321
If I have a code in Go like this:
package main
import "fmt"
import "log"
func main() {
fmt.Println("hello world")
log.Println("log hello world")
}
is it possible to run this program suppressing the log output without change the source code, passing a flag or env variable from command line like for example QUIET=1 go run hello
?
Upvotes: 1
Views: 1295
Reputation: 1977
You can either have the shell discard the output using go run hello 2>/dev/null
(as @TimCooper mentioned in the comments), or you can overwrite the output of the log
package by calling log.SetOutput()
and passing an implementation of io.Writer
that discards the input (or writes it to whatever you want).
Upvotes: 1