mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-06-28 20:01:39 +00:00
Pull request 2590: AGDNS-3564-agh-debug
Squashed commit of the following:
commit b53e3b92d06440837b0896d56aabcd31aa25a1b2
Merge: 30ee12832 d9445795f
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Thu Feb 26 17:10:45 2026 +0300
Merge branch 'master' into AGDNS-3564-agh-debug
commit 30ee128326912391bf3d469ddd2b9f9716bdc6f1
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Thu Feb 26 11:01:28 2026 +0300
home: refactor logger configuring;
commit 46c8806ef23e568da47f4b0a314fa4bc38a85f1c
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Wed Feb 25 13:27:57 2026 +0300
all: fix changelog
commit 62001a7acaf347016974846416b8462f7ab48134
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Wed Feb 25 12:27:20 2026 +0300
all: add changes to the changelog
commit c41318d8e4b54e942902907ae696b8d06926d464
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Fri Feb 20 17:06:31 2026 +0300
home: rename logger to l; VERBOSE=1
commit 2d4b33e526dfc12b94f9684698836f0af3650e05
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date: Fri Feb 20 14:53:25 2026 +0300
home: init logger level in newSlogLogger;
This commit is contained in:
parent
d9445795f9
commit
f2032b0f39
3 changed files with 23 additions and 30 deletions
|
|
@ -17,6 +17,11 @@ See also the [v0.107.73 GitHub milestone][ms-v0.107.73].
|
|||
|
||||
NOTE: Add new changes BELOW THIS COMMENT.
|
||||
-->
|
||||
|
||||
### Fixed
|
||||
|
||||
- Incorrect logger behavior in case `-v` flag is added.
|
||||
|
||||
<!--
|
||||
NOTE: Add new changes ABOVE THIS COMMENT.
|
||||
-->
|
||||
|
|
|
|||
|
|
@ -108,6 +108,17 @@ func Main(clientBuildFS fs.FS) {
|
|||
// TODO(a.garipov): Use slog everywhere.
|
||||
baseLogger := newSlogLogger(ls)
|
||||
|
||||
// Configure log level and output.
|
||||
err = configureLogger(ls, workDir)
|
||||
fatalOnError(err)
|
||||
|
||||
// Print the first message after logger is configured.
|
||||
baseLogger.InfoContext(ctx, "starting adguard home", "version", version.Full())
|
||||
baseLogger.DebugContext(ctx, "current working directory", "path", workDir)
|
||||
if opts.runningAsService {
|
||||
baseLogger.InfoContext(ctx, "adguard home is running as a service")
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
|
|
@ -732,7 +743,7 @@ func run(
|
|||
workDir string,
|
||||
confPath string,
|
||||
) {
|
||||
initEnvironment(ctx, opts, baseLogger, workDir, confPath)
|
||||
aghtls.Init(ctx, baseLogger.With(slogutil.KeyPrefix, "aghtls"))
|
||||
|
||||
isFirstRun := detectFirstRun(ctx, baseLogger, workDir, confPath)
|
||||
|
||||
|
|
@ -953,31 +964,6 @@ func initUpdate(
|
|||
return upd, isCustomURL
|
||||
}
|
||||
|
||||
// initEnvironment inits working environment. opts and slogLogger must not be
|
||||
// nil.
|
||||
func initEnvironment(
|
||||
ctx context.Context,
|
||||
opts options,
|
||||
slogLogger *slog.Logger,
|
||||
workDir,
|
||||
confPath string,
|
||||
) {
|
||||
ls := getLogSettings(ctx, slogLogger, opts, workDir, confPath)
|
||||
|
||||
// Configure log level and output.
|
||||
err := configureLogger(ls, workDir)
|
||||
fatalOnError(err)
|
||||
|
||||
// Print the first message after logger is configured.
|
||||
slogLogger.InfoContext(ctx, "starting adguard home", "version", version.Full())
|
||||
slogLogger.DebugContext(ctx, "current working directory", "path", workDir)
|
||||
if opts.runningAsService {
|
||||
slogLogger.InfoContext(ctx, "adguard home is running as a service")
|
||||
}
|
||||
|
||||
aghtls.Init(ctx, slogLogger.With(slogutil.KeyPrefix, "aghtls"))
|
||||
}
|
||||
|
||||
// newUpdater creates a new AdGuard Home updater. l and conf must not be nil.
|
||||
// workDir, confPath, and execPath must not be empty. isCustomURL is true if
|
||||
// the user has specified a custom version announcement URL.
|
||||
|
|
|
|||
|
|
@ -31,15 +31,12 @@ func newSlogLogger(ls *logSettings) (l *slog.Logger) {
|
|||
lvl = slog.LevelDebug
|
||||
}
|
||||
|
||||
return slogutil.New(&slogutil.Config{
|
||||
l = slogutil.New(&slogutil.Config{
|
||||
Format: slogutil.FormatAdGuardLegacy,
|
||||
Level: lvl,
|
||||
AddTimestamp: true,
|
||||
})
|
||||
}
|
||||
|
||||
// configureLogger configures logger level and output. ls must not be nil.
|
||||
func configureLogger(ls *logSettings, workDir string) (err error) {
|
||||
// Configure logger level.
|
||||
if !ls.Enabled {
|
||||
log.SetLevel(log.OFF)
|
||||
|
|
@ -47,6 +44,11 @@ func configureLogger(ls *logSettings, workDir string) (err error) {
|
|||
log.SetLevel(log.DEBUG)
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// configureLogger configures logger output. ls must not be nil.
|
||||
func configureLogger(ls *logSettings, workDir string) (err error) {
|
||||
// Make sure that we see the microseconds in logs, as networking stuff can
|
||||
// happen pretty quickly.
|
||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue