Skip to content

Commit 9f5ae0e

Browse files
authored
Merge pull request #37 from blinklabs-io/feat/querylog
feat: query logging
2 parents b3abc06 + 0eb121a commit 9f5ae0e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Config struct {
3838
type LoggingConfig struct {
3939
Healthchecks bool `yaml:"healthchecks" envconfig:"LOGGING_HEALTHCHECKS"`
4040
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
41+
QueryLog bool `yaml:"queryLog" envconfig:"LOGGING_QUERY_LOG"`
4142
}
4243

4344
type DnsConfig struct {
@@ -76,6 +77,7 @@ var globalConfig = &Config{
7677
Logging: LoggingConfig{
7778
Level: "info",
7879
Healthchecks: false,
80+
QueryLog: true,
7981
},
8082
Dns: DnsConfig{
8183
ListenAddress: "",

internal/dns/dns.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) {
3838
cfg := config.GetConfig()
3939
m := new(dns.Msg)
4040

41+
if cfg.Logging.QueryLog {
42+
for _, q := range r.Question {
43+
logger.Infof("query: name: %s, type: %s, class: %s",
44+
q.Name,
45+
dns.Type(q.Qtype).String(),
46+
dns.Class(q.Qclass).String(),
47+
)
48+
}
49+
}
50+
4151
// Split query name into labels and lookup each domain and parent until we get a hit
4252
queryLabels := dns.SplitDomainName(r.Question[0].Name)
4353
for startLabelIdx := 0; startLabelIdx < len(queryLabels); startLabelIdx++ {

0 commit comments

Comments
 (0)