2019-08-26 08:54:38 +00:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
// QueryLog - main interface
|
|
|
|
type QueryLog interface {
|
2019-09-04 11:12:00 +00:00
|
|
|
// Close query log object
|
2019-08-26 08:54:38 +00:00
|
|
|
Close()
|
|
|
|
|
|
|
|
// Set new configuration at runtime
|
|
|
|
// Currently only 'Interval' field is supported.
|
|
|
|
Configure(conf Config)
|
|
|
|
|
2019-09-04 11:12:00 +00:00
|
|
|
// Add a log entry
|
2019-08-26 08:54:38 +00:00
|
|
|
Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string)
|
2019-09-04 11:12:00 +00:00
|
|
|
|
|
|
|
// Get log entries
|
2019-08-26 08:54:38 +00:00
|
|
|
GetData() []map[string]interface{}
|
2019-09-04 11:12:00 +00:00
|
|
|
|
|
|
|
// Clear memory buffer and remove log files
|
2019-08-26 08:54:38 +00:00
|
|
|
Clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config - configuration object
|
|
|
|
type Config struct {
|
|
|
|
BaseDir string // directory where log file is stored
|
|
|
|
Interval uint32 // interval to rotate logs (in hours)
|
|
|
|
}
|
|
|
|
|
2019-09-04 11:12:00 +00:00
|
|
|
// New - create a new instance of the query log
|
2019-08-26 08:54:38 +00:00
|
|
|
func New(conf Config) QueryLog {
|
|
|
|
return newQueryLog(conf)
|
|
|
|
}
|