Skip to content

Commit

Permalink
+ config: new setting "querylog_file_enabled" - query log will be wri…
Browse files Browse the repository at this point in the history
…tten to a file
  • Loading branch information
szolin committed May 27, 2020
1 parent 355e634 commit 03ca280
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
13 changes: 8 additions & 5 deletions home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ type dnsConfig struct {
// time interval for statistics (in days)
StatsInterval uint32 `yaml:"statistics_interval"`

QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled
QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days)
QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk
AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats
QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled
QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file
QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days)
QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk
AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats

dnsforward.FilteringConfig `yaml:",inline"`

Expand Down Expand Up @@ -138,6 +139,7 @@ func initConfig() {
config.WebSessionTTLHours = 30 * 24

config.DNS.QueryLogEnabled = true
config.DNS.QueryLogFileEnabled = true
config.DNS.QueryLogInterval = 90
config.DNS.QueryLogMemSize = 1000

Expand Down Expand Up @@ -239,9 +241,10 @@ func (c *configuration) write() error {
}

if Context.queryLog != nil {
dc := querylog.DiskConfig{}
dc := querylog.Config{}
Context.queryLog.WriteDiskConfig(&dc)
config.DNS.QueryLogEnabled = dc.Enabled
config.DNS.QueryLogFileEnabled = dc.FileEnabled
config.DNS.QueryLogInterval = dc.Interval
config.DNS.QueryLogMemSize = dc.MemSize
config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP
Expand Down
1 change: 1 addition & 0 deletions home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func initDNSServer() error {
}
conf := querylog.Config{
Enabled: config.DNS.QueryLogEnabled,
FileEnabled: config.DNS.QueryLogFileEnabled,
BaseDir: baseDir,
Interval: config.DNS.QueryLogInterval,
MemSize: config.DNS.QueryLogMemSize,
Expand Down
7 changes: 2 additions & 5 deletions querylog/qlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ func checkInterval(days uint32) bool {
return days == 1 || days == 7 || days == 30 || days == 90
}

func (l *queryLog) WriteDiskConfig(dc *DiskConfig) {
dc.Enabled = l.conf.Enabled
dc.Interval = l.conf.Interval
dc.MemSize = l.conf.MemSize
dc.AnonymizeClientIP = l.conf.AnonymizeClientIP
func (l *queryLog) WriteDiskConfig(c *Config) {
*c = *l.conf
}

// Clear memory buffer and remove log files
Expand Down
11 changes: 2 additions & 9 deletions querylog/querylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ import (
"github.com/miekg/dns"
)

// DiskConfig - configuration settings that are stored on disk
type DiskConfig struct {
Enabled bool
Interval uint32
MemSize uint32
AnonymizeClientIP bool
}

// QueryLog - main interface
type QueryLog interface {
Start()
Expand All @@ -28,12 +20,13 @@ type QueryLog interface {
Add(params AddParams)

// WriteDiskConfig - write configuration
WriteDiskConfig(dc *DiskConfig)
WriteDiskConfig(c *Config)
}

// Config - configuration object
type Config struct {
Enabled bool
FileEnabled bool
BaseDir string // directory where log file is stored
Interval uint32 // interval to rotate logs (in days)
MemSize uint32 // number of entries kept in memory before they are flushed to disk
Expand Down
4 changes: 4 additions & 0 deletions querylog/querylog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

// flushLogBuffer flushes the current buffer to file and resets the current buffer
func (l *queryLog) flushLogBuffer(fullFlush bool) error {
if !l.conf.FileEnabled {
return nil
}

l.fileFlushLock.Lock()
defer l.fileFlushLock.Unlock()

Expand Down

0 comments on commit 03ca280

Please sign in to comment.