Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: query logging #37

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
type LoggingConfig struct {
Healthchecks bool `yaml:"healthchecks" envconfig:"LOGGING_HEALTHCHECKS"`
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
QueryLog bool `yaml:"queryLog" envconfig:"LOGGING_QUERY_LOG"`
}

type DnsConfig struct {
Expand Down Expand Up @@ -76,6 +77,7 @@ var globalConfig = &Config{
Logging: LoggingConfig{
Level: "info",
Healthchecks: false,
QueryLog: true,
},
Dns: DnsConfig{
ListenAddress: "",
Expand Down
10 changes: 10 additions & 0 deletions internal/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) {
cfg := config.GetConfig()
m := new(dns.Msg)

if cfg.Logging.QueryLog {
for _, q := range r.Question {
logger.Infof("query: name: %s, type: %s, class: %s",
q.Name,
dns.Type(q.Qtype).String(),
dns.Class(q.Qclass).String(),
)
}
}

// Split query name into labels and lookup each domain and parent until we get a hit
queryLabels := dns.SplitDomainName(r.Question[0].Name)
for startLabelIdx := 0; startLabelIdx < len(queryLabels); startLabelIdx++ {
Expand Down
Loading