~bayindirh/nudge

0196967a50e931b5ab3397ff965c9cdfba5ba84c — Hakan Bayindir 7 months ago 5160de3
refactor: Remove verbosity related plumbing.

All code related to verbosity alteration is removed from the code, since having logging level settings is enough.

Verbosity would make things more complicated for no benefit.
2 files changed, 2 insertions(+), 9 deletions(-)

M CHANGELOG.md
M src/nudge.go
M CHANGELOG.md => CHANGELOG.md +1 -0
@@ 4,6 4,7 @@

## 2023-07-15

- refactor: Remove verbosity settings related plumbing from code. Will use logging level only.
- fix: Store settings obtained via `initFlags` in the correct data structure (`FlagStorage` instead of `NotificationToSend`).
- refactor: Use `flag.Lookup()` instead of manually checking everything, which was not very reliable.
- feat: `applyFlags` function is implemented completely.

M src/nudge.go => src/nudge.go +1 -9
@@ 59,7 59,6 @@ type RuntimeConfiguration struct {
	userKey         string   // Secret key of the user, used as a recipient address.
	logfilePaths    []string // Contains the absolute path for the logfile.
	logLevel        string   // Contains the logging level the application starts with.
	verbosity       int      // Stores the requested log verbosity over the base log level.
}

// Following struct is for temporarily storing flag values passed during program invocation.


@@ 122,7 121,6 @@ func applyDefaultConfiguration(runtimeConfiguration *RuntimeConfiguration, notif
	runtimeConfiguration.dryrun = false
	runtimeConfiguration.logfilePaths = []string{"stdout"}
	runtimeConfiguration.logLevel = "info"
	runtimeConfiguration.verbosity = 0
}

// This function reads the configuration file and applies it to relevant data structures.


@@ 226,11 224,6 @@ func initFlags(notificationToSend *Notification, flagStorage *FlagStorage, logge
	// Get logging level and save it.
	flag.StringVar(&flagStorage.logLevel, "log_level", flagStorage.logLevel, "Change the logging level.")

	// Following flags are for controlling the output & verbosity.
	// TODO: Will be implemented in version 0.2
	// flag.IntVar(&runtimeConfiguration.verbosity, "verbosity", 1, "Set verbosity level. Between -1 and 5.")
	// flag.StringVar(&runtimeConfiguration.logfilePath, "logfile_path", "", "Define the path of the log file.")

	// Following flag is for controlling the place of the configuration file.
	flag.StringVar(&flagStorage.configFilePath, "config_path", flagStorage.configFilePath, "Define or override configuration file path.")



@@ 342,8 335,7 @@ func printState(runtimeConfiguration *RuntimeConfiguration, notification *Notifi
	logger.Infof("Pushover API key: %s", runtimeConfiguration.apiKey)
	logger.Infof("Pushover user key: %s", runtimeConfiguration.userKey)
	logger.Infof("Log file path: %s", runtimeConfiguration.logfilePaths)
	logger.Infof("Log verbosity: %d", runtimeConfiguration.verbosity)

	logger.Infof("Current logging level is %s.", runtimeConfiguration.logLevel)
	logger.Infof("") // Leave an empty line.

	// Dump notification in a different block.