mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 10:58:29 -07:00
32d1f385ff
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
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package querylog
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// QueryLog - main interface
|
|
type QueryLog interface {
|
|
Start()
|
|
|
|
// Close query log object
|
|
Close()
|
|
|
|
// Add a log entry
|
|
Add(params AddParams)
|
|
|
|
// WriteDiskConfig - write configuration
|
|
WriteDiskConfig(c *Config)
|
|
}
|
|
|
|
// Config - configuration object
|
|
type Config struct {
|
|
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
|
|
AnonymizeClientIP bool // anonymize clients' IP addresses
|
|
|
|
// Called when the configuration is changed by HTTP request
|
|
ConfigModified func()
|
|
|
|
// Register an HTTP handler
|
|
HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request))
|
|
}
|
|
|
|
// AddParams - parameters for Add()
|
|
type AddParams struct {
|
|
Question *dns.Msg
|
|
Answer *dns.Msg // The response we sent to the client (optional)
|
|
OrigAnswer *dns.Msg // The response from an upstream server (optional)
|
|
Result *dnsfilter.Result // Filtering result (optional)
|
|
Elapsed time.Duration // Time spent for processing the request
|
|
ClientIP net.IP
|
|
Upstream string
|
|
}
|
|
|
|
// New - create a new instance of the query log
|
|
func New(conf Config) QueryLog {
|
|
return newQueryLog(conf)
|
|
}
|