The http.Server
type in the golang standard net/http
package has a field named ErrorLog
, which is of type log.Logger
.
This is how ErrorLog
is set up in my http.Server
:
// set up HTTP server
server = &http.Server{
Addr: getPortFromConfig(),
Handler: handler,
ErrorLog: log.New(io.MultiWriter(stdout, fileout), "", 1),
}
So here, the io.MultiWriter()
function creates a new io.Writer
that will copy all writes from my http.Server
into a file as well as stdout. It works like a charm.
However, I would like to intercept the data and format it before it is written to the file.
How is it possible to do this?