Reputation: 9806
When using the built-in http module in Go, I notice that http.ListenAndServe()
will make logging calls to stdout
by default. The main thing showing up in my terminal is:
http: TLS handshake error from x.x.x.x:x: tls: client offered an unsupported, maximum protocol version of 301.
Now I understand what this error is and what causes it, but the fact of the matter is, I don't particularly care.
How can I stop the http package (or ListenAndServe()
, whatever) from logging to stdout by default? It's clogging up my pretty console. I'm 95% certain that I'm not the one logging the messages as all of the logs I have setup have "INFO", "WARNING" etc prefixes on them.
Upvotes: 2
Views: 1110
Reputation: 240649
It doesn't log to stdout, it logs to the http server's ErrorLog
if it's set, and to the standard logger (the one used by the non-method functions in log) otherwise. If you have a logger already, construct a http.Server
with that logger as its ErrorLog
and call ListenAndServe
on that. Otherwise use log.SetOutput
to change the destination of the standard log.
Upvotes: 4