+ config: new setting "querylog_file_enabled"
Close #876
Squashed commit of the following:
commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8
Merge: cfb72869 391e6199
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu May 28 15:17:21 2020 +0300
Merge remote-tracking branch 'origin/master' into 876-logs
commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9
Author: Simon Zolin <s.zolin@adguard.com>
Date: Thu May 28 12:50:02 2020 +0300
tests
commit 35376e4f450cf66507d733c931b7ed27eff1f36c
Author: Simon Zolin <s.zolin@adguard.com>
Date: Wed May 27 18:15:12 2020 +0300
fix
commit 0cfb802d73db52a4b09c459a68a8a18918447b76
Author: Simon Zolin <s.zolin@adguard.com>
Date: Wed May 27 16:49:52 2020 +0300
tests
commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6
Author: Simon Zolin <s.zolin@adguard.com>
Date: Wed May 27 15:32:27 2020 +0300
+ config: new setting "querylog_file_enabled" - query log will be written to a file
This commit is contained in:
@@ -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
|
||||
@@ -152,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
|
||||
@@ -162,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)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user