Skip to content

Commit

Permalink
all: log enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Jun 20, 2024
1 parent 08d863d commit 7658c9b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -454,6 +457,7 @@ var config = &configuration{
},
},
Log: logSettings{
Enabled: true,
Compress: false,
LocalTime: false,
MaxBackups: 0,
Expand Down
11 changes: 9 additions & 2 deletions internal/home/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7658c9b

Please sign in to comment.