How can I set logging level for golang glog package to ERROR.
example.go:
package main
import (
"github.com/golang/glog"
"flag"
)
func main() {
flag.Parse()
glog.Info("Info level")
glog.Error("Error level")
glog.Flush()
}
$ go run example.go -logtostderr=true -stderrthreshold=ERROR
I1214 15:46:00.743002 13429 example.go:10] Info level
E1214 15:46:00.743211 13429 example.go:11] Error level
In the above example I have set the stderrthreshold flag to ERROR but am still getting INFO level logs. I want only ERROR level logs.
By default, glog will write
/tmpby default);stderrthresholdor above to stderr.By using the
-logtostderr=trueflag this behaviour is changed:The
stderrthresholdpresumably has no effect when-logtostderr=trueis used. And in your invocation it didn't have an effect anyway, because the default threshold is alreadyERROR.To summarize, by just running
go run example.gowithout any command line arguments, only log messages with severityERRORor above are written to stderr, as you desired.