Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
szolin committed May 27, 2020
1 parent 0cfb802 commit 35376e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions querylog/qlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}()
}
}
4 changes: 2 additions & 2 deletions querylog/querylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35376e4

Please sign in to comment.