From 7658c9b107f109c391b6bd5407098e8e53754842 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Thu, 20 Jun 2024 14:17:08 +0300 Subject: [PATCH] all: log enabled --- CHANGELOG.md | 6 ++++++ internal/home/config.go | 4 ++++ internal/home/log.go | 11 +++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 284fe8bb28b..50aa2cb5182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,11 @@ See also the [v0.107.52 GitHub milestone][ms-v0.107.52]. NOTE: Add new changes BELOW THIS COMMENT. --> +### Added + +- The ability to disable logging using the new `log.enabled` configuration + property ([#7079]). + ### Changed - Frontend rewritten in TypeScript. @@ -59,6 +64,7 @@ NOTE: Add new changes BELOW THIS COMMENT. [#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053 [#7069]: https://github.com/AdguardTeam/AdGuardHome/issues/7069 [#7076]: https://github.com/AdguardTeam/AdGuardHome/issues/7076 +[#7079]: https://github.com/AdguardTeam/AdGuardHome/issues/7079 [install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac diff --git a/internal/home/config.go b/internal/home/config.go index ba9c00d9fe4..ab9f4ef194a 100644 --- a/internal/home/config.go +++ b/internal/home/config.go @@ -32,6 +32,9 @@ const dataDir = "data" // logSettings are the logging settings part of the configuration file. type logSettings struct { + // Enabled indicates whether logging is enabled. + Enabled bool `yaml:"enabled"` + // File is the path to the log file. If empty, logs are written to stdout. // If "syslog", logs are written to syslog. File string `yaml:"file"` @@ -454,6 +457,7 @@ var config = &configuration{ }, }, Log: logSettings{ + Enabled: true, Compress: false, LocalTime: false, MaxBackups: 0, diff --git a/internal/home/log.go b/internal/home/log.go index efc90d3f9c8..15354b82fd3 100644 --- a/internal/home/log.go +++ b/internal/home/log.go @@ -21,7 +21,9 @@ func configureLogger(opts options) (err error) { ls := getLogSettings(opts) // Configure logger level. - if ls.Verbose { + if !ls.Enabled { + log.SetLevel(log.OFF) + } else if ls.Verbose { log.SetLevel(log.DEBUG) } @@ -91,7 +93,12 @@ func getLogSettings(opts options) (ls *logSettings) { // separate method in order to configure logger before the actual configuration // is parsed and applied. func readLogSettings() (ls *logSettings) { - conf := &configuration{} + conf := &configuration{ + Log: logSettings{ + // By default, it is true if the property does not exist. + Enabled: true, + }, + } yamlFile, err := readConfigFile() if err != nil {