mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 16:54:15 -04:00
log DoH HTTP server error logs in CoreDNS format (#5457)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
stdlog "log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
"github.com/coredns/coredns/plugin/metrics/vars"
|
"github.com/coredns/coredns/plugin/metrics/vars"
|
||||||
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
"github.com/coredns/coredns/plugin/pkg/doh"
|
"github.com/coredns/coredns/plugin/pkg/doh"
|
||||||
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
"github.com/coredns/coredns/plugin/pkg/response"
|
"github.com/coredns/coredns/plugin/pkg/response"
|
||||||
"github.com/coredns/coredns/plugin/pkg/reuseport"
|
"github.com/coredns/coredns/plugin/pkg/reuseport"
|
||||||
"github.com/coredns/coredns/plugin/pkg/transport"
|
"github.com/coredns/coredns/plugin/pkg/transport"
|
||||||
@@ -27,6 +29,15 @@ type ServerHTTPS struct {
|
|||||||
validRequest func(*http.Request) bool
|
validRequest func(*http.Request) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loggerAdapter is a simple adapter around CoreDNS logger made to implement io.Writer in order to log errors from HTTP server
|
||||||
|
type loggerAdapter struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loggerAdapter) Write(p []byte) (n int, err error) {
|
||||||
|
clog.Debug(string(p))
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
// HTTPRequestKey is the context key for the current processed HTTP request (if current processed request was done over DOH)
|
// HTTPRequestKey is the context key for the current processed HTTP request (if current processed request was done over DOH)
|
||||||
type HTTPRequestKey struct{}
|
type HTTPRequestKey struct{}
|
||||||
|
|
||||||
@@ -63,6 +74,7 @@ func NewServerHTTPS(addr string, group []*Config) (*ServerHTTPS, error) {
|
|||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: 10 * time.Second,
|
||||||
IdleTimeout: 120 * time.Second,
|
IdleTimeout: 120 * time.Second,
|
||||||
|
ErrorLog: stdlog.New(&loggerAdapter{}, "", 0),
|
||||||
}
|
}
|
||||||
sh := &ServerHTTPS{
|
sh := &ServerHTTPS{
|
||||||
Server: s, tlsConfig: tlsConfig, httpsServer: srv, validRequest: validator,
|
Server: s, tlsConfig: tlsConfig, httpsServer: srv, validRequest: validator,
|
||||||
|
|||||||
Reference in New Issue
Block a user