/
log.go
32 lines (28 loc) · 903 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package server
import (
stdlibLog "log"
"net"
"net/http"
"github.com/go-kit/kit/log"
"github.com/xmidt-org/webpa-common/logging"
)
// NewErrorLog creates a new logging.Logger appropriate for http.Server.ErrorLog
func NewErrorLog(serverName string, logger log.Logger) *stdlibLog.Logger {
return stdlibLog.New(
log.NewStdlibAdapter(logger),
serverName,
stdlibLog.LstdFlags|stdlibLog.LUTC,
)
}
// NewConnectionStateLogger produces a function appropriate for http.Server.ConnState.
// The returned function will log debug statements for each state change.
func NewConnectionStateLogger(serverName string, logger log.Logger) func(net.Conn, http.ConnState) {
logger = logging.Debug(logger)
return func(connection net.Conn, connectionState http.ConnState) {
logger.Log(
"serverName", serverName,
"localAddress", connection.LocalAddr().String(),
"state", connectionState,
)
}
}