Migrate to structured logging (klog)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-09-27 17:32:40 -03:00
parent 93ac8d5a21
commit 108637bb1c
31 changed files with 161 additions and 171 deletions

View file

@ -63,19 +63,19 @@ func (p *TCPProxy) Handle(conn net.Conn) {
length, err := conn.Read(data)
if err != nil {
klog.V(4).Infof("Error reading the first 4k of the connection: %v", err)
klog.V(4).ErrorS(err, "Error reading the first 4k of the connection")
return
}
proxy := p.Default
hostname, err := parser.GetHostname(data[:])
if err == nil {
klog.V(4).Infof("Parsed hostname from TLS Client Hello: %s", hostname)
klog.V(4).InfoS("TLS Client Hello", "host", hostname)
proxy = p.Get(hostname)
}
if proxy == nil {
klog.V(4).Info("There is no configured proxy for SSL connections.")
klog.V(4).InfoS("There is no configured proxy for SSL connections.")
return
}
@ -97,11 +97,11 @@ func (p *TCPProxy) Handle(conn net.Conn) {
protocol = "TCP6"
}
proxyProtocolHeader := fmt.Sprintf("PROXY %s %s %s %d %d\r\n", protocol, remoteAddr.IP.String(), localAddr.IP.String(), remoteAddr.Port, localAddr.Port)
klog.V(4).Infof("Writing Proxy Protocol header: %s", proxyProtocolHeader)
klog.V(4).InfoS("Writing Proxy Protocol", "header", proxyProtocolHeader)
_, err = fmt.Fprintf(clientConn, proxyProtocolHeader)
}
if err != nil {
klog.Errorf("Error writing Proxy Protocol header: %v", err)
klog.ErrorS(err, "Error writing Proxy Protocol header")
clientConn.Close()
} else {
_, err = clientConn.Write(data[:length])