aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ondřej Benkovský <ondrej.benkovsky@jamf.com> 2022-06-23 21:46:42 +0200
committerGravatar GitHub <noreply@github.com> 2022-06-23 15:46:42 -0400
commitd7f8202dc3cb9c2d66e2d98dd9d84f708eed4d13 (patch)
treec1f80041d438804ab07c2e11419efb69614996d8
parent89ff12b412914ed598ee7cfab9a7d4803e67514d (diff)
downloadcoredns-d7f8202dc3cb9c2d66e2d98dd9d84f708eed4d13.tar.gz
coredns-d7f8202dc3cb9c2d66e2d98dd9d84f708eed4d13.tar.zst
coredns-d7f8202dc3cb9c2d66e2d98dd9d84f708eed4d13.zip
log DoH HTTP server error logs in CoreDNS format (#5457)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
-rw-r--r--core/dnsserver/server_https.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/dnsserver/server_https.go b/core/dnsserver/server_https.go
index 5c884e56b..b8b32b52e 100644
--- a/core/dnsserver/server_https.go
+++ b/core/dnsserver/server_https.go
@@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
+ stdlog "log"
"net"
"net/http"
"strconv"
@@ -13,6 +14,7 @@ import (
"github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
"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/reuseport"
"github.com/coredns/coredns/plugin/pkg/transport"
@@ -27,6 +29,15 @@ type ServerHTTPS struct {
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)
type HTTPRequestKey struct{}
@@ -63,6 +74,7 @@ func NewServerHTTPS(addr string, group []*Config) (*ServerHTTPS, error) {
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
+ ErrorLog: stdlog.New(&loggerAdapter{}, "", 0),
}
sh := &ServerHTTPS{
Server: s, tlsConfig: tlsConfig, httpsServer: srv, validRequest: validator,