Pull request 2242: 7079-log-enabled

Updates #7079.

Squashed commit of the following:

commit 477c5ed29c8066dc9cb175809572f613b2a0dfa0
Merge: d3c64e03a 647214092
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Jun 20 19:31:54 2024 +0300

    Merge branch 'master' into 7079-log-enabled

commit d3c64e03a5
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Jun 20 16:02:42 2024 +0300

    home: imp docs

commit 7658c9b107
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Jun 20 14:17:08 2024 +0300

    all: log enabled
This commit is contained in:
Stanislav Chzhen 2024-06-20 19:44:51 +03:00
parent 6472140920
commit 65b7d232ab
3 changed files with 25 additions and 4 deletions

View File

@ -27,6 +27,11 @@ See also the [v0.107.52 GitHub milestone][ms-v0.107.52].
NOTE: Add new changes BELOW THIS COMMENT. NOTE: Add new changes BELOW THIS COMMENT.
--> -->
### Added
- The ability to disable logging using the new `log.enabled` configuration
property ([#7079]).
### Changed ### Changed
- Frontend rewritten in TypeScript. - Frontend rewritten in TypeScript.
@ -59,6 +64,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
[#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053 [#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053
[#7069]: https://github.com/AdguardTeam/AdGuardHome/issues/7069 [#7069]: https://github.com/AdguardTeam/AdGuardHome/issues/7069
[#7076]: https://github.com/AdguardTeam/AdGuardHome/issues/7076 [#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 [install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac

View File

@ -32,6 +32,9 @@ const dataDir = "data"
// logSettings are the logging settings part of the configuration file. // logSettings are the logging settings part of the configuration file.
type logSettings struct { 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. // File is the path to the log file. If empty, logs are written to stdout.
// If "syslog", logs are written to syslog. // If "syslog", logs are written to syslog.
File string `yaml:"file"` File string `yaml:"file"`
@ -454,11 +457,14 @@ var config = &configuration{
}, },
}, },
Log: logSettings{ Log: logSettings{
Compress: false, Enabled: true,
LocalTime: false, File: "",
MaxBackups: 0, MaxBackups: 0,
MaxSize: 100, MaxSize: 100,
MaxAge: 3, MaxAge: 3,
Compress: false,
LocalTime: false,
Verbose: false,
}, },
OSConfig: &osConfig{}, OSConfig: &osConfig{},
SchemaVersion: configmigrate.LastSchemaVersion, SchemaVersion: configmigrate.LastSchemaVersion,

View File

@ -21,7 +21,9 @@ func configureLogger(opts options) (err error) {
ls := getLogSettings(opts) ls := getLogSettings(opts)
// Configure logger level. // Configure logger level.
if ls.Verbose { if !ls.Enabled {
log.SetLevel(log.OFF)
} else if ls.Verbose {
log.SetLevel(log.DEBUG) log.SetLevel(log.DEBUG)
} }
@ -91,7 +93,14 @@ func getLogSettings(opts options) (ls *logSettings) {
// separate method in order to configure logger before the actual configuration // separate method in order to configure logger before the actual configuration
// is parsed and applied. // is parsed and applied.
func readLogSettings() (ls *logSettings) { func readLogSettings() (ls *logSettings) {
conf := &configuration{} // TODO(s.chzhen): Add a helper function that returns default parameters
// for this structure and for the global configuration structure [config].
conf := &configuration{
Log: logSettings{
// By default, it is true if the property does not exist.
Enabled: true,
},
}
yamlFile, err := readConfigFile() yamlFile, err := readConfigFile()
if err != nil { if err != nil {