all: slog logger

This commit is contained in:
Dimitry Kolyshev 2024-07-05 11:05:14 +03:00
parent 9a74d5d98b
commit 3d7f734ac9
6 changed files with 102 additions and 33 deletions
internal/home

View file

@ -38,6 +38,7 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/hostsfile"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/osutil"
)
@ -547,15 +548,21 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
// Configure config filename.
initConfigFilename(opts)
ls := getLogSettings(opts)
// Configure log level and output.
err = configureLogger(opts)
err = configureLogger(ls)
fatalOnError(err)
// Configure slog logger.
l, err := initLogger(ls)
fatalOnError(err)
// Print the first message after logger is configured.
log.Info(version.Full())
log.Debug("current working directory is %s", Context.workDir)
l.Info(version.Full())
l.Debug("current working directory is set", "work_dir", Context.workDir)
if opts.runningAsService {
log.Info("AdGuard Home is running as a service")
l.Info("AdGuard Home is running as a service")
}
err = setupContext(opts)
@ -586,7 +593,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
}
confPath := configFilePath()
log.Debug("using config path %q for updater", confPath)
l.Debug("using config path for updater", "path", confPath)
upd := updater.NewUpdater(&updater.Config{
Client: config.Filtering.HTTPClient,
@ -628,7 +635,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
Context.tls, err = newTLSManager(config.TLS, config.DNS.ServePlainDNS)
if err != nil {
log.Error("initializing tls: %s", err)
l.Error("initializing tls", slogutil.KeyError, err)
onConfigModified()
}
@ -652,7 +659,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
if Context.dhcpServer != nil {
err = Context.dhcpServer.Start()
if err != nil {
log.Error("starting dhcp server: %s", err)
l.Error("starting dhcp server", slogutil.KeyError, err)
}
}
}