diff --git a/querylog/qlog.go b/querylog/qlog.go index d000d1128e3..27bcc01eb7f 100644 --- a/querylog/qlog.go +++ b/querylog/qlog.go @@ -149,7 +149,14 @@ func (l *queryLog) Add(params AddParams) { l.bufferLock.Lock() l.buffer = append(l.buffer, &entry) needFlush := false - if !l.flushPending { + + if !l.conf.FileEnabled { + if len(l.buffer) > int(l.conf.MemSize) { + // writing to file is disabled - just remove the oldest entry from array + l.buffer = l.buffer[1:] + } + + } else if !l.flushPending { needFlush = len(l.buffer) >= int(l.conf.MemSize) if needFlush { l.flushPending = true @@ -159,8 +166,8 @@ func (l *queryLog) Add(params AddParams) { // if buffer needs to be flushed to disk, do it now if needFlush { - // write to file - // do it in separate goroutine -- we are stalling DNS response this whole time - go l.flushLogBuffer(false) // nolint + go func() { + _ = l.flushLogBuffer(false) + }() } } diff --git a/querylog/querylog.go b/querylog/querylog.go index e1a97415378..2fa7ac9d339 100644 --- a/querylog/querylog.go +++ b/querylog/querylog.go @@ -25,8 +25,8 @@ type QueryLog interface { // Config - configuration object type Config struct { - Enabled bool - FileEnabled bool + Enabled bool // enable the module + FileEnabled bool // write logs to file 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