fix: log warning when no config file is found

Always log the configuration source at startup: shows an INFO message with the
config file path when found, or a WARN message explaining how to specify one
when not found. This helps users understand why CLI commands may fail when
run outside of systemd (where --configfile is typically specified).

Closes #4758
This commit is contained in:
Deluan
2025-12-02 14:24:15 -05:00
parent 13f6eb9a11
commit 142a3136d4

View File

@@ -340,9 +340,16 @@ func Load(noConfigDump bool) {
Server.BaseScheme = u.Scheme Server.BaseScheme = u.Scheme
} }
// Log configuration source
if Server.ConfigFile != "" {
log.Info("Loaded configuration", "file", Server.ConfigFile)
} else {
log.Warn("No configuration file found. Using default values. To specify a config file, use the --configfile flag or set the ND_CONFIGFILE environment variable.")
}
// Print current configuration if log level is Debug // Print current configuration if log level is Debug
if log.IsGreaterOrEqualTo(log.LevelDebug) && !noConfigDump { if log.IsGreaterOrEqualTo(log.LevelDebug) && !noConfigDump {
prettyConf := pretty.Sprintf("Loaded configuration from '%s': %# v", Server.ConfigFile, Server) prettyConf := pretty.Sprintf("Configuration: %# v", Server)
if Server.EnableLogRedacting { if Server.EnableLogRedacting {
prettyConf = log.Redact(prettyConf) prettyConf = log.Redact(prettyConf)
} }