Pull request 2304: AGDNS-2374-slog-querylog

Squashed commit of the following:

commit e98e5efaaf5388551322933321df0707ad7b2a9c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Nov 21 13:15:51 2024 +0300

    all: imp code

commit fbe728c9aa03a325c2733c214412f9071faba5ed
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Nov 18 20:57:15 2024 +0300

    all: imp code

commit ef715c58cb6621236424f55268390aa3f997f883
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Nov 18 16:39:35 2024 +0300

    all: imp code

commit cbb993f7ae4311b2a73ace7066a5dabf190291be
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Nov 18 14:03:42 2024 +0300

    all: imp code

commit 8d88d799303c7e3d15322fee87780fedb408ea13
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Nov 15 15:57:07 2024 +0300

    all: slog querylog
This commit is contained in:
Stanislav Chzhen
2024-11-21 20:19:39 +03:00
parent 1d6d85cff4
commit d96e65cb0c
18 changed files with 524 additions and 236 deletions

View File

@@ -2,6 +2,7 @@ package querylog
import (
"fmt"
"log/slog"
"net"
"path/filepath"
"sync"
@@ -12,20 +13,19 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/container"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/service"
"github.com/miekg/dns"
)
// QueryLog - main interface
// QueryLog is the query log interface for use by other packages.
type QueryLog interface {
Start()
// Interface starts and stops the query log.
service.Interface
// Close query log object
Close()
// Add a log entry
// Add adds a log entry.
Add(params *AddParams)
// WriteDiskConfig - write configuration
// WriteDiskConfig writes the query log configuration to c.
WriteDiskConfig(c *Config)
// ShouldLog returns true if request for the host should be logged.
@@ -36,6 +36,10 @@ type QueryLog interface {
//
// Do not alter any fields of this structure after using it.
type Config struct {
// Logger is used for logging the operation of the query log. It must not
// be nil.
Logger *slog.Logger
// Ignored contains the list of host names, which should not be written to
// log, and matches them.
Ignored *aghnet.IgnoreEngine
@@ -151,6 +155,7 @@ func newQueryLog(conf Config) (l *queryLog, err error) {
}
l = &queryLog{
logger: conf.Logger,
findClient: findClient,
buffer: container.NewRingBuffer[*logEntry](memSize),