From fca0faf6d4b0500ce36e225d67d291ddff1da5f2 Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev Date: Wed, 9 Jul 2025 12:07:37 +0300 Subject: [PATCH] Pull request: AGDNS-3007-fix-ups-logger Merge in DNS/adguard-home from AGDNS-3007-fix-ups-logger to master Squashed commit of the following: commit 7b198ab6f075ec0be9ab638925d65dcf16c3aa67 Author: Dimitry Kolyshev Date: Wed Jul 9 09:54:15 2025 +0400 dnsforward: fix merge commit dd0a680bd1b995bbe570861723f85244855de2ce Merge: 081526039 63c64b10e Author: Dimitry Kolyshev Date: Wed Jul 9 09:43:22 2025 +0400 Merge remote-tracking branch 'origin/master' into AGDNS-3007-fix-ups-logger commit 081526039fb7841ca2ca94f3effe339bfb01d295 Author: Dimitry Kolyshev Date: Mon Jul 7 17:53:37 2025 +0400 all: imp code commit 88b5398c8b2dce1b942ed239d488fc9dc2d342ab Author: Dimitry Kolyshev Date: Thu Jul 3 09:59:28 2025 +0400 all: imp code commit c9440af9a5a21f16d126b0d494a21537fda0d339 Author: Dimitry Kolyshev Date: Thu Jul 3 09:51:44 2025 +0400 all: imp code commit 4aff2860eda8f5050bc0450f6c7027b1da451ab8 Author: Dimitry Kolyshev Date: Wed Jul 2 13:41:00 2025 +0400 all: upstream dnsproxy prefix commit 4cbc65608ec9431b6e4380a5e931cf3300b18fd0 Author: Dimitry Kolyshev Date: Wed Jul 2 13:37:45 2025 +0400 aghslog: add dnsproxy prefix commit fdc1ed02c380e6687fafbac973f74f461974d1d2 Author: Dimitry Kolyshev Date: Wed Jul 2 13:33:10 2025 +0400 client: imp upstream log commit 19438ba7e8497dc7753180d60202afa620b22df9 Author: Dimitry Kolyshev Date: Wed Jul 2 13:30:10 2025 +0400 all: aghslog consts commit ee5e3875c7af342412b03240cbc8c0699f431de4 Author: Dimitry Kolyshev Date: Wed Jul 2 13:26:42 2025 +0400 dnsforward: imp tests commit 8b8c608032658897742df38910d7f5370a26adaa Author: Dimitry Kolyshev Date: Tue Jul 1 14:04:59 2025 +0400 client: fix upd conf logger commit 98227476a21fc305e9ecf62be60f1af992bac36f Author: Dimitry Kolyshev Date: Tue Jul 1 13:26:09 2025 +0400 next: dnssvc: use aghslog constants commit b331ba921cac60cdd7dac6a169c7e071acba5b2b Author: Dimitry Kolyshev Date: Tue Jul 1 13:23:33 2025 +0400 all: fix upd conf logger --- internal/aghslog/aghslog.go | 52 +++++++++++++++++++ internal/client/persistent.go | 5 +- internal/client/storage.go | 8 ++- internal/client/storage_test.go | 44 ++++++++++------ internal/client/upstreammanager.go | 30 ++++++++--- internal/dnsforward/config.go | 3 +- internal/dnsforward/dnsforward.go | 7 ++- .../dnsforward/dnsforward_internal_test.go | 11 ++-- internal/dnsforward/http.go | 11 +++- .../dnsforward/upstreams_internal_test.go | 2 + internal/home/clients.go | 1 + internal/home/home.go | 2 + internal/home/tls_internal_test.go | 10 ++-- internal/next/dnssvc/dnssvc.go | 9 ++-- 14 files changed, 152 insertions(+), 43 deletions(-) create mode 100644 internal/aghslog/aghslog.go diff --git a/internal/aghslog/aghslog.go b/internal/aghslog/aghslog.go new file mode 100644 index 00000000..c307f344 --- /dev/null +++ b/internal/aghslog/aghslog.go @@ -0,0 +1,52 @@ +// Package aghslog contains logging constants and helpers. +package aghslog + +import ( + "log/slog" + + "github.com/AdguardTeam/golibs/logutil/slogutil" +) + +// PrefixDNSProxy is the prefix for DNS proxy logs. +const PrefixDNSProxy = "dnsproxy" + +const ( + // KeyClientName is the log attribute for the client name. + KeyClientName = "client_name" + + // KeyUpstreamType is the log attribute for the upstream types. See the + // UpstreamType* constants below. + KeyUpstreamType = "upstream_type" +) + +const ( + // UpstreamTypeBootstrap is the log attribute value for bootstrap upstreams. + UpstreamTypeBootstrap = "bootstrap" + + // UpstreamTypeCustom is the log attribute value for custom upstreams. + UpstreamTypeCustom = "custom" + + // UpstreamTypeFallback is the log attribute value for fallback upstreams. + UpstreamTypeFallback = "fallback" + + // UpstreamTypeMain is the log attribute value for main upstreams. + UpstreamTypeMain = "main" + + // UpstreamTypeLocal is the log attribute value for upstreams used for + // resolving PTR records for local addresses. + UpstreamTypeLocal = "local" + + // UpstreamTypeService is the log attribute value for upstreams used for + // safe browsing and parental services. + UpstreamTypeService = "service" + + // UpstreamTypeTest is the log attribute value for upstreams used for + // testing and validation. + UpstreamTypeTest = "test" +) + +// NewForUpstream returns a new logger with a prefix for logs related to a +// specific upstream type. +func NewForUpstream(baseLogger *slog.Logger, typ string) (l *slog.Logger) { + return baseLogger.With(slogutil.KeyPrefix, PrefixDNSProxy, KeyUpstreamType, typ) +} diff --git a/internal/client/persistent.go b/internal/client/persistent.go index 145dcc4b..1d1967a2 100644 --- a/internal/client/persistent.go +++ b/internal/client/persistent.go @@ -10,6 +10,7 @@ import ( "slices" "strings" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" @@ -142,7 +143,9 @@ func (c *Persistent) validate(ctx context.Context, l *slog.Logger, allTags []str return errors.Error("uid required") } - conf, err := proxy.ParseUpstreamsConfig(c.Upstreams, &upstream.Options{}) + conf, err := proxy.ParseUpstreamsConfig(c.Upstreams, &upstream.Options{ + Logger: l.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeTest), + }) if err != nil { return fmt.Errorf("invalid upstream servers: %w", err) } diff --git a/internal/client/storage.go b/internal/client/storage.go index 734394d7..4ec327ad 100644 --- a/internal/client/storage.go +++ b/internal/client/storage.go @@ -88,6 +88,10 @@ type HostsContainer interface { // StorageConfig is the client storage configuration structure. type StorageConfig struct { + // BaseLogger is used to create loggers for other entities. It should not + // have a prefix and must not be nil. + BaseLogger *slog.Logger + // Logger is used for logging the operation of the client storage. It must // not be nil. Logger *slog.Logger @@ -174,7 +178,7 @@ func NewStorage(ctx context.Context, conf *StorageConfig) (s *Storage, err error mu: &sync.Mutex{}, index: newIndex(), runtimeIndex: newRuntimeIndex(), - upstreamManager: newUpstreamManager(conf.Logger, conf.Clock), + upstreamManager: newUpstreamManager(conf.BaseLogger, conf.Clock), dhcp: conf.DHCP, etcHosts: conf.EtcHosts, arpDB: conf.ARPDB, @@ -739,7 +743,7 @@ func (s *Storage) CustomUpstreamConfig( return nil } - return s.upstreamManager.customUpstreamConfig(c.UID) + return s.upstreamManager.customUpstreamConfig(c.UID, c.Name) } // UpdateCommonUpstreamConfig implements the [dnsforward.ClientsContainer] diff --git a/internal/client/storage_test.go b/internal/client/storage_test.go index b1f68e41..f7d95715 100644 --- a/internal/client/storage_test.go +++ b/internal/client/storage_test.go @@ -25,14 +25,18 @@ import ( "github.com/stretchr/testify/require" ) +// testLogger is a logger used in tests. +var testLogger = slogutil.NewDiscardLogger() + // newTestStorage is a helper function that returns initialized storage. func newTestStorage(tb testing.TB, clock timeutil.Clock) (s *client.Storage) { tb.Helper() ctx := testutil.ContextWithTimeout(tb, testTimeout) s, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - Clock: clock, + BaseLogger: testLogger, + Logger: testLogger, + Clock: clock, }) require.NoError(tb, err) @@ -134,7 +138,8 @@ func TestStorage_Add_hostsfile(t *testing.T) { ctx := testutil.ContextWithTimeout(t, testTimeout) storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), + BaseLogger: testLogger, + Logger: testLogger, DHCP: client.EmptyDHCP{}, EtcHosts: h, ARPClientsUpdatePeriod: testTimeout / 10, @@ -224,7 +229,8 @@ func TestStorage_Add_arp(t *testing.T) { ctx := testutil.ContextWithTimeout(t, testTimeout) storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), + BaseLogger: testLogger, + Logger: testLogger, DHCP: client.EmptyDHCP{}, ARPDB: a, ARPClientsUpdatePeriod: testTimeout / 10, @@ -301,8 +307,9 @@ func TestStorage_Add_whois(t *testing.T) { ctx := testutil.ContextWithTimeout(t, testTimeout) storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - DHCP: client.EmptyDHCP{}, + BaseLogger: testLogger, + Logger: testLogger, + DHCP: client.EmptyDHCP{}, }) require.NoError(t, err) @@ -417,7 +424,8 @@ func TestClientsDHCP(t *testing.T) { ctx := testutil.ContextWithTimeout(t, testTimeout) storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), + BaseLogger: testLogger, + Logger: testLogger, ARPDB: arpDB, DHCP: dhcp, EtcHosts: etcHosts, @@ -566,8 +574,9 @@ func TestClientsAddExisting(t *testing.T) { t.Run("simple", func(t *testing.T) { storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - DHCP: client.EmptyDHCP{}, + BaseLogger: testLogger, + Logger: testLogger, + DHCP: client.EmptyDHCP{}, }) require.NoError(t, err) @@ -613,8 +622,9 @@ func TestClientsAddExisting(t *testing.T) { require.NoError(t, err) storage, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - DHCP: dhcpServer, + BaseLogger: testLogger, + Logger: testLogger, + DHCP: dhcpServer, }) require.NoError(t, err) @@ -653,8 +663,9 @@ func newStorage(tb testing.TB, m []*client.Persistent) (s *client.Storage) { ctx := testutil.ContextWithTimeout(tb, testTimeout) s, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - DHCP: client.EmptyDHCP{}, + BaseLogger: testLogger, + Logger: testLogger, + DHCP: client.EmptyDHCP{}, }) require.NoError(tb, err) @@ -1210,9 +1221,10 @@ func TestStorage_CustomUpstreamConfig(t *testing.T) { ctx := testutil.ContextWithTimeout(t, testTimeout) s, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - Clock: clock, - DHCP: dhcp, + BaseLogger: testLogger, + Logger: testLogger, + Clock: clock, + DHCP: dhcp, }) require.NoError(t, err) diff --git a/internal/client/upstreammanager.go b/internal/client/upstreammanager.go index 38ad4231..3c571741 100644 --- a/internal/client/upstreammanager.go +++ b/internal/client/upstreammanager.go @@ -7,6 +7,7 @@ import ( "time" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/errors" @@ -56,10 +57,12 @@ type customUpstreamConfig struct { // upstreamManager stores and updates custom client upstream configurations. type upstreamManager struct { + // baseLogger is used to create loggers for client upstream configurations. + // It should not have a prefix and must not be nil. + baseLogger *slog.Logger + // logger is used for logging the operation of the upstream manager. It // must not be nil. - // - // TODO(s.chzhen): Consider using a logger with its own prefix. logger *slog.Logger // uidToCustomConf maps persistent client UID to the custom client upstream @@ -78,9 +81,10 @@ type upstreamManager struct { } // newUpstreamManager returns the new properly initialized upstream manager. -func newUpstreamManager(logger *slog.Logger, clock timeutil.Clock) (m *upstreamManager) { +func newUpstreamManager(baseLogger *slog.Logger, clock timeutil.Clock) (m *upstreamManager) { return &upstreamManager{ - logger: logger, + baseLogger: baseLogger, + logger: baseLogger.With(slogutil.KeyPrefix, "upstream_manager"), uidToCustomConf: make(map[UID]*customUpstreamConfig), clock: clock, } @@ -115,7 +119,10 @@ func (m *upstreamManager) updateCustomUpstreamConfig(c *Persistent) { } // customUpstreamConfig returns the custom client upstream configuration. -func (m *upstreamManager) customUpstreamConfig(uid UID) (proxyConf *proxy.CustomUpstreamConfig) { +func (m *upstreamManager) customUpstreamConfig( + uid UID, + clientName string, +) (proxyConf *proxy.CustomUpstreamConfig) { cliConf, ok := m.uidToCustomConf[uid] if !ok { // TODO(s.chzhen): Consider panic. @@ -136,7 +143,11 @@ func (m *upstreamManager) customUpstreamConfig(uid UID) (proxyConf *proxy.Custom } } - proxyConf = newCustomUpstreamConfig(cliConf, m.commonConf) + cliLogger := aghslog.NewForUpstream(m.baseLogger, aghslog.UpstreamTypeCustom).With( + aghslog.KeyClientName, + clientName, + ) + proxyConf = newCustomUpstreamConfig(cliConf, m.commonConf, cliLogger) cliConf.proxyConf = proxyConf cliConf.commonConfUpdate = m.confUpdate cliConf.isChanged = false @@ -193,10 +204,12 @@ func (m *upstreamManager) close() (err error) { } // newCustomUpstreamConfig returns the new properly initialized custom proxy -// upstream configuration for the client. +// upstream configuration for the client. cliConf, conf, and cliLogger must not +// be nil. func newCustomUpstreamConfig( cliConf *customUpstreamConfig, conf *CommonUpstreamConfig, + cliLogger *slog.Logger, ) (proxyConf *proxy.CustomUpstreamConfig) { upstreams := stringutil.FilterOut(cliConf.upstreams, aghnet.IsCommentOrEmpty) if len(upstreams) == 0 { @@ -206,8 +219,9 @@ func newCustomUpstreamConfig( upsConf, err := proxy.ParseUpstreamsConfig( upstreams, &upstream.Options{ + Logger: cliLogger, Bootstrap: conf.Bootstrap, - Timeout: time.Duration(conf.UpstreamTimeout), + Timeout: conf.UpstreamTimeout, HTTPVersions: aghnet.UpstreamHTTPVersions(conf.UseHTTP3Upstreams), PreferIPv6: conf.BootstrapPreferIPv6, }, diff --git a/internal/dnsforward/config.go b/internal/dnsforward/config.go index 198b7702..a5d83c6c 100644 --- a/internal/dnsforward/config.go +++ b/internal/dnsforward/config.go @@ -13,6 +13,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/aghtls" "github.com/AdguardTeam/AdGuardHome/internal/client" "github.com/AdguardTeam/dnsproxy/proxy" @@ -311,7 +312,7 @@ func (s *Server) newProxyConfig() (conf *proxy.Config, err error) { trustedPrefixes := netutil.UnembedPrefixes(srvConf.TrustedProxies) conf = &proxy.Config{ - Logger: s.baseLogger.With(slogutil.KeyPrefix, "dnsproxy"), + Logger: s.baseLogger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy), HTTP3: srvConf.ServeHTTP3, Ratelimit: int(srvConf.Ratelimit), RatelimitSubnetLenIPv4: srvConf.RatelimitSubnetLenIPv4, diff --git a/internal/dnsforward/dnsforward.go b/internal/dnsforward/dnsforward.go index 2f695d7a..05814288 100644 --- a/internal/dnsforward/dnsforward.go +++ b/internal/dnsforward/dnsforward.go @@ -18,6 +18,7 @@ import ( "time" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/client" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/AdGuardHome/internal/querylog" @@ -546,6 +547,7 @@ func (s *Server) prepareUpstreamSettings(boot upstream.Resolver) (err error) { } uc, err := newUpstreamConfig(upstreams, defaultDNS, &upstream.Options{ + Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeMain), Bootstrap: boot, Timeout: s.conf.UpstreamTimeout, HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams), @@ -612,6 +614,7 @@ func (s *Server) prepareLocalResolvers() (uc *proxy.UpstreamConfig, err error) { } opts := &upstream.Options{ + Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeLocal), Bootstrap: s.bootstrap, Timeout: defaultLocalTimeout, // TODO(e.burkov): Should we verify server's certificates? @@ -644,6 +647,7 @@ func (s *Server) prepareInternalDNS() (err error) { } bootOpts := &upstream.Options{ + Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeBootstrap), Timeout: DefaultTimeout, HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams), } @@ -682,6 +686,7 @@ func (s *Server) setupFallbackDNS() (uc *proxy.UpstreamConfig, err error) { } uc, err = proxy.ParseUpstreamsConfig(fallbacks, &upstream.Options{ + Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeFallback), // TODO(s.chzhen): Investigate if other options are needed. Timeout: s.conf.UpstreamTimeout, PreferIPv6: s.conf.BootstrapPreferIPv6, @@ -750,7 +755,7 @@ func validateBlockingMode( func (s *Server) prepareInternalProxy() (err error) { srvConf := s.conf conf := &proxy.Config{ - Logger: s.baseLogger.With(slogutil.KeyPrefix, "dnsproxy"), + Logger: s.baseLogger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy), CacheEnabled: true, CacheSizeBytes: 4096, PrivateRDNSUpstreamConfig: srvConf.PrivateRDNSUpstreamConfig, diff --git a/internal/dnsforward/dnsforward_internal_test.go b/internal/dnsforward/dnsforward_internal_test.go index 8263b63c..53be7bbc 100644 --- a/internal/dnsforward/dnsforward_internal_test.go +++ b/internal/dnsforward/dnsforward_internal_test.go @@ -39,6 +39,9 @@ import ( "github.com/stretchr/testify/require" ) +// testLogger is a logger used in tests. +var testLogger = slogutil.NewDiscardLogger() + func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) } @@ -63,9 +66,6 @@ const ( // TODO(a.garipov): Use more. var testClientAddrPort = netip.MustParseAddrPort("1.2.3.4:12345") -// testLogger is the common logger for tests. -var testLogger = slogutil.NewDiscardLogger() - // type check var _ ClientsContainer = (*clientsContainer)(nil) @@ -532,7 +532,10 @@ func TestDoQServer(t *testing.T) { // Create a DNS-over-QUIC upstream. addr := s.dnsProxy.Addr(proxy.ProtoQUIC) - opts := &upstream.Options{InsecureSkipVerify: true} + opts := &upstream.Options{ + Logger: testLogger, + InsecureSkipVerify: true, + } u, err := upstream.AddressToUpstream(fmt.Sprintf("%s://%s", proxy.ProtoQUIC, addr), opts) require.NoError(t, err) diff --git a/internal/dnsforward/http.go b/internal/dnsforward/http.go index cfa428cb..59f3fde8 100644 --- a/internal/dnsforward/http.go +++ b/internal/dnsforward/http.go @@ -12,11 +12,13 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/golibs/validate" @@ -366,7 +368,9 @@ func (req *jsonDNSConfig) checkPrivateRDNS( addrs := cmp.Or(req.LocalPTRUpstreams, &[]string{}) - uc, err := newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, &upstream.Options{}) + uc, err := newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, &upstream.Options{ + Logger: slogutil.NewDiscardLogger(), + }) err = errors.WithDeferred(err, uc.Close()) if err != nil { return fmt.Errorf("private upstream servers: %w", err) @@ -382,7 +386,9 @@ func (req *jsonDNSConfig) validateUpstreamDNSServers( privateNets netutil.SubnetSet, ) (err error) { var uc *proxy.UpstreamConfig - opts := &upstream.Options{} + opts := &upstream.Options{ + Logger: slogutil.NewDiscardLogger(), + } if req.Upstreams != nil { uc, err = proxy.ParseUpstreamsConfig(*req.Upstreams, opts) @@ -651,6 +657,7 @@ func (s *Server) handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) { req.BootstrapDNS = stringutil.FilterOut(req.BootstrapDNS, aghnet.IsCommentOrEmpty) opts := &upstream.Options{ + Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeTest), Timeout: s.conf.UpstreamTimeout, PreferIPv6: s.conf.BootstrapPreferIPv6, } diff --git a/internal/dnsforward/upstreams_internal_test.go b/internal/dnsforward/upstreams_internal_test.go index 128c3eeb..4dbd289a 100644 --- a/internal/dnsforward/upstreams_internal_test.go +++ b/internal/dnsforward/upstreams_internal_test.go @@ -144,6 +144,7 @@ func TestUpstreamConfigValidator(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { cv := newUpstreamConfigValidator(tc.general, tc.fallback, tc.private, &upstream.Options{ + Logger: testLogger, Timeout: upsTimeout, Bootstrap: net.DefaultResolver, }) @@ -195,6 +196,7 @@ func TestUpstreamConfigValidator_Check_once(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { cv := newUpstreamConfigValidator(tc.ups, nil, nil, &upstream.Options{ + Logger: testLogger, Timeout: testTimeout, }) diff --git a/internal/home/clients.go b/internal/home/clients.go index 208b326b..e6459342 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -112,6 +112,7 @@ func (clients *clientsContainer) Init( } clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{ + BaseLogger: baseLogger, Logger: baseLogger.With(slogutil.KeyPrefix, "client_storage"), Clock: timeutil.SystemClock{}, InitialClients: confClients, diff --git a/internal/home/home.go b/internal/home/home.go index d4b6322a..f38a350f 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -21,6 +21,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghalg" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/AdGuardHome/internal/aghos" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/arpdb" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" @@ -385,6 +386,7 @@ func setupDNSFilteringConf( cacheTime := time.Duration(conf.CacheTime) * time.Minute upsOpts := &upstream.Options{ + Logger: aghslog.NewForUpstream(baseLogger, aghslog.UpstreamTypeService), Timeout: dnsTimeout, Bootstrap: upstream.StaticResolver{ // 94.140.14.15. diff --git a/internal/home/tls_internal_test.go b/internal/home/tls_internal_test.go index 6ce1782f..b65d0a97 100644 --- a/internal/home/tls_internal_test.go +++ b/internal/home/tls_internal_test.go @@ -230,8 +230,9 @@ func TestTLSManager_Reload(t *testing.T) { require.NoError(t, err) globalContext.clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{ - Logger: testLogger, - Clock: timeutil.SystemClock{}, + BaseLogger: testLogger, + Logger: testLogger, + Clock: timeutil.SystemClock{}, }) require.NoError(t, err) @@ -492,8 +493,9 @@ func TestTLSManager_HandleTLSConfigure(t *testing.T) { require.NoError(t, err) globalContext.clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{ - Logger: testLogger, - Clock: timeutil.SystemClock{}, + BaseLogger: testLogger, + Logger: testLogger, + Clock: timeutil.SystemClock{}, }) require.NoError(t, err) diff --git a/internal/next/dnssvc/dnssvc.go b/internal/next/dnssvc/dnssvc.go index 10cce3e9..1d74a8f6 100644 --- a/internal/next/dnssvc/dnssvc.go +++ b/internal/next/dnssvc/dnssvc.go @@ -14,10 +14,12 @@ import ( "time" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/AdGuardHome/internal/aghslog" "github.com/AdguardTeam/AdGuardHome/internal/next/agh" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/errors" + "github.com/AdguardTeam/golibs/logutil/slogutil" ) // Service is the AdGuard Home DNS service. A nil *Service is a valid @@ -78,7 +80,7 @@ func New(c *Config) (svc *Service, err error) { } upstreams, resolvers, err := addressesToUpstreams( - svc.logger, + svc.logger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy), c.UpstreamServers, c.BootstrapServers, c.UpstreamTimeout, @@ -122,8 +124,7 @@ func addressesToUpstreams( preferIPv6 bool, ) (upstreams []upstream.Upstream, boots []*upstream.UpstreamResolver, err error) { boots, err = aghnet.ParseBootstraps(bootstraps, &upstream.Options{ - // TODO(d.kolyshev): Use consts. - Logger: logger.With("upstream_type", "bootstrap"), + Logger: logger.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeBootstrap), Timeout: timeout, PreferIPv6: preferIPv6, }) @@ -141,7 +142,7 @@ func addressesToUpstreams( upstreams = make([]upstream.Upstream, len(upsStrs)) for i, upsStr := range upsStrs { upstreams[i], err = upstream.AddressToUpstream(upsStr, &upstream.Options{ - Logger: logger.With("upstream_type", "main"), + Logger: logger.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeMain), Bootstrap: bootstrap, Timeout: timeout, PreferIPv6: preferIPv6,