Add opt-in JSON logging with structured DNS query fields (#8553)

* plugin/pkg/log: add opt-in JSON logging backend

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>

* plugin/log: emit typed query records in JSON mode

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>

* coremain: expose process-wide JSON logging

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>

---------

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
houyuwushang
2026-09-17 08:50:39 +08:00
committed by GitHub
parent 84a93a0b89
commit b93e449b2f
20 changed files with 1064 additions and 22 deletions

View File

@@ -7,8 +7,17 @@ import (
"strings"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/log"
)
func printStartup(out string) {
if log.IsJSON() {
log.Info(strings.TrimSuffix(out, "\n"))
return
}
fmt.Print(out)
}
// checkZoneSyntax() checks whether the given string match 1035 Preferred Syntax or not.
// The root zone, and all reverse zones always return true even though they technically don't meet 1035 Preferred Syntax
func checkZoneSyntax(zone string) bool {

View File

@@ -43,7 +43,6 @@ package dnsserver
import (
"context"
"fmt"
"maps"
"net"
"runtime/debug"
@@ -504,7 +503,7 @@ func (s *Server) OnStartupComplete() {
out := startUpZones("", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}

View File

@@ -156,7 +156,7 @@ func (s *ServergRPC) OnStartupComplete() {
out := startUpZones(transport.GRPC+"://", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}

View File

@@ -185,7 +185,7 @@ func (s *ServerHTTPS) OnStartupComplete() {
out := startUpZones(transport.HTTPS+"://", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}

View File

@@ -203,7 +203,7 @@ func (s *ServerHTTPS3) OnStartupComplete() {
}
out := startUpZones(transport.HTTPS3+"://", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}

View File

@@ -315,7 +315,7 @@ func (s *ServerQUIC) OnStartupComplete() {
out := startUpZones(transport.QUIC+"://", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}

View File

@@ -3,7 +3,6 @@ package dnsserver
import (
"context"
"crypto/tls"
"fmt"
"net"
"time"
@@ -100,6 +99,6 @@ func (s *ServerTLS) OnStartupComplete() {
out := startUpZones(transport.TLS+"://", s.Addr, s.zones)
if out != "" {
fmt.Print(out)
printStartup(out)
}
}