From 9bc93f8a2bde4301193770e20bb66d785bf0ab41 Mon Sep 17 00:00:00 2001 From: Tom Cole Date: Thu, 23 Jan 2025 17:41:10 -0500 Subject: [PATCH 1/2] fix: allow localized log messages to include newlines --- i18n/subs.go | 3 +++ runtime/rest/exchange.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/i18n/subs.go b/i18n/subs.go index f7edf0db..16f68ea3 100644 --- a/i18n/subs.go +++ b/i18n/subs.go @@ -12,6 +12,9 @@ func HandleSubstitutionMap(text string, valueMap map[string]interface{}) string return text } + // Before we get cranking, fix any escaped newlines. + text = strings.ReplaceAll(text, "\\n", "\n") + return handleSubstitutionMap(text, valueMap) } diff --git a/runtime/rest/exchange.go b/runtime/rest/exchange.go index c36a6c5f..dc6efa4e 100644 --- a/runtime/rest/exchange.go +++ b/runtime/rest/exchange.go @@ -110,7 +110,7 @@ func Exchange(endpoint, method string, body interface{}, response interface{}, a } if replyMedia := restResponse.Header().Get("Content-Type"); replyMedia != "" { - ui.Log(ui.RestLogger, "rest.repy.media", + ui.Log(ui.RestLogger, "rest.reply.media", "media", replyMedia) } From bf47ce9e7a654918d796ca73edda43a54503e193 Mon Sep 17 00:00:00 2001 From: Tom Cole Date: Thu, 23 Jan 2025 18:10:29 -0500 Subject: [PATCH 2/2] fix: correct errors in info logging for logs, config set logging --- app-cli/settings/files.go | 152 ++++++++++++++++++------------------- app-cli/settings/values.go | 14 ++-- app-cli/ui/logfile.go | 20 ++--- commands/server.go | 12 +-- tools/buildver.txt | 2 +- 5 files changed, 101 insertions(+), 99 deletions(-) diff --git a/app-cli/settings/files.go b/app-cli/settings/files.go index 571d0d18..cd5e76a1 100644 --- a/app-cli/settings/files.go +++ b/app-cli/settings/files.go @@ -110,8 +110,8 @@ func Load(application string, name string) error { return errors.New(err) } - ui.Log(ui.AppLogger, "config.active", - "name", name) + ui.Log(ui.AppLogger, "config.active", ui.A{ + "name": name}) // Do we already have that configuration loaded? If so make it current // and we're done. @@ -119,15 +119,15 @@ func Load(application string, name string) error { path := filepath.Join(home, ProfileDirectory, name+".profile") CurrentConfiguration = c - ui.Log(ui.AppLogger, "config.base.loaded", - "path", path) + ui.Log(ui.AppLogger, "config.base.loaded", ui.A{ + "path": path}) // For any keys that are stored as separate file values, get them now. readOutboardConfigFiles(home, name, c) - ui.Log(ui.AppLogger, "config.is.active", - "name", CurrentConfiguration.Name, - "id", CurrentConfiguration.ID) + ui.Log(ui.AppLogger, "config.is.active", ui.A{ + "Name": CurrentConfiguration.Name, + "id": CurrentConfiguration.ID}) return nil } @@ -142,8 +142,8 @@ func Load(application string, name string) error { path := filepath.Join(home, ProfileDirectory) if _, err := os.Stat(path); os.IsNotExist(err) { _ = os.MkdirAll(path, securePermission) - ui.Log(ui.AppLogger, "config.create.dir", - "path", path) + ui.Log(ui.AppLogger, "config.create.dir", ui.A{ + "path": path}) } // Read legacy configuration file if it exists. @@ -157,8 +157,8 @@ func Load(application string, name string) error { for _, file := range files { configFile, err := os.Open(file) if err == nil { - ui.Log(ui.AppLogger, "config.read.profile", - "path", file) + ui.Log(ui.AppLogger, "config.read.profile", ui.A{ + "path": file}) defer configFile.Close() byteValue, _ := io.ReadAll(configFile) @@ -171,10 +171,10 @@ func Load(application string, name string) error { profile.Name = shortProfileName Configurations[shortProfileName] = &profile - ui.Log(ui.AppLogger, "config.loaded.config", - "name", profile.Name, - "id", profile.ID, - "count", len(profile.Items)) + ui.Log(ui.AppLogger, "config.loaded.config", ui.A{ + "name": profile.Name, + "id": profile.ID, + "count": len(profile.Items)}) } } } @@ -184,8 +184,8 @@ func Load(application string, name string) error { // default configuration. cp, found := Configurations[name] if !found { - ui.Log(ui.AppLogger, "config.not.found", - "name", name) + ui.Log(ui.AppLogger, "config.not.found", ui.A{ + "name": name}) cp = &Configuration{ Description: DefaultConfiguration, @@ -196,9 +196,9 @@ func Load(application string, name string) error { } Configurations[name] = cp } else { - ui.Log(ui.AppLogger, "config.using", - "name", name, - "id", cp.ID) + ui.Log(ui.AppLogger, "config.using", ui.A{ + "name": name, + "id": cp.ID}) } ProfileName = cp.Name @@ -246,9 +246,9 @@ func readOutboardConfigFiles(home string, name string, cp *Configuration) { if err == nil { var value string - ui.Log(ui.AppLogger, "config.external", - "name", token, - "path", fileName) + ui.Log(ui.AppLogger, "config.external", ui.A{ + "name": token, + "path": fileName}) err := json.Unmarshal(bytes, &value) if err == nil && len(value) > 0 { @@ -256,14 +256,14 @@ func readOutboardConfigFiles(home string, name string, cp *Configuration) { if strings.HasPrefix(value, encryptionPrefixTag) { value, err = Decrypt(strings.TrimPrefix(value, encryptionPrefixTag), cp.Name+cp.Salt+cp.ID) if err != nil { - ui.Log(ui.AppLogger, "config.decrypt.error", - "name", token, - "error", err) + ui.Log(ui.AppLogger, "config.decrypt.error", ui.A{ + "name": token, + "error": err}) continue } else { - ui.Log(ui.AppLogger, "config.decrypted", - "name", token) + ui.Log(ui.AppLogger, "config.decrypted", ui.A{ + "name": token}) } } @@ -283,8 +283,8 @@ func readLegacyConfigFormat(path string, home string, name string) (error, strin if err == nil { // read the json config as a byte array. defer configFile.Close() - ui.Log(ui.AppLogger, "config.legacy.read", - "path", path) + ui.Log(ui.AppLogger, "config.legacy.read", ui.A{ + "path": path}) byteValue, _ := io.ReadAll(configFile) @@ -301,10 +301,10 @@ func readLegacyConfigFormat(path string, home string, name string) (error, strin p.Dirty = true p.Name = profileName Configurations[profileName] = p - ui.Log(ui.AppLogger, "config.legacy.load", - "name", profileName, - "id", p.ID, - "count", len(p.Items)) + ui.Log(ui.AppLogger, "config.legacy.load", ui.A{ + "name": profileName, + "id": p.ID, + "count": len(p.Items)}) } } } else { @@ -364,18 +364,18 @@ func Save() error { if err != nil { err = errors.New(err) - ui.Log(ui.AppLogger, "config.save.error", - "name", name, - "error", err) + ui.Log(ui.AppLogger, "config.save.error", ui.A{ + "name": name, + "error": err}) break } else { Configurations[name] = profile - ui.Log(ui.AppLogger, "config.save", - "name", name, - "id", profile.ID, - "path", path) + ui.Log(ui.AppLogger, "config.save", ui.A{ + "name": name, + "id": profile.ID, + "path": path}) } } @@ -396,8 +396,8 @@ func Save() error { // Write any keys that are intended to be stored outside the configuration into separate files. func saveOutboardConfigItems(profile *Configuration, home string, name string, err error, savedItems map[string]string) { for token, file := range fileMapping { - ui.Log(ui.AppLogger, "config.external.check", - "name", token) + ui.Log(ui.AppLogger, "config.external.check", ui.A{ + "name": token}) // We only do this for key values that exist and are non-empty. if value, ok := profile.Items[token]; ok && len(value) > 0 { @@ -406,14 +406,14 @@ func saveOutboardConfigItems(profile *Configuration, home string, name string, e // Encrypt the value using the salt as the password value, err = Encrypt(value, profile.Name+profile.Salt+profile.ID) if err != nil { - ui.Log(ui.AppLogger, "config.external.encrypt.error", - "name", token, - "error", err) + ui.Log(ui.AppLogger, "config.external.encrypt.error", ui.A{ + "name": token, + "error": err}) continue } else { - ui.Log(ui.AppLogger, "config.external.encxrypt", - "name", token) + ui.Log(ui.AppLogger, "config.external.encxrypt", ui.A{ + "name": token}) value = encryptionPrefixTag + value } @@ -431,19 +431,19 @@ func saveOutboardConfigItems(profile *Configuration, home string, name string, e if err != nil { err = errors.New(err) - ui.Log(ui.AppLogger, "config.external.write.error", - "name", token, - "path", fileName, - "error", err) + ui.Log(ui.AppLogger, "config.external.write.error", ui.A{ + "name": token, + "path": fileName, + "error": err}) break } else { savedItems[token] = profile.Items[token] delete(profile.Items, token) - ui.Log(ui.AppLogger, "config.extenral.write", - "name", token, - "path", fileName) + ui.Log(ui.AppLogger, "config.extenral.write", ui.A{ + "name": token, + "path": fileName}) } } } else { @@ -453,15 +453,15 @@ func saveOutboardConfigItems(profile *Configuration, home string, name string, e err := os.Remove(fileName) if err == nil { - ui.Log(ui.AppLogger, "config.external.deleted", - "path", fileName) + ui.Log(ui.AppLogger, "config.external.deleted", ui.A{ + "path": fileName}) } else if !goerr.Is(err, fs.ErrNotExist) { - ui.Log(ui.AppLogger, "config.external.delete.error", - "path", fileName, - "error", err) + ui.Log(ui.AppLogger, "config.external.delete.error", ui.A{ + "path": fileName, + "error": err}) } else { - ui.Log(ui.AppLogger, "config.external.not.found", - "path", fileName) + ui.Log(ui.AppLogger, "config.external.not.found", ui.A{ + "path": fileName}) } } } @@ -509,9 +509,9 @@ func DeleteProfile(key string) error { // profiles need to be refreshed on disk. path := filepath.Join(home, ProfileDirectory, key+".profile") if err = os.Remove(path); err != nil { - ui.Log(ui.AppLogger, "config.delete.error", - "path", path, - "error", err) + ui.Log(ui.AppLogger, "config.delete.error", ui.A{ + "path": path, + "error": err}) } else { err = Save() } @@ -523,29 +523,29 @@ func DeleteProfile(key string) error { if _, err := os.Stat(fileName); err == nil { err = os.Remove(fileName) if err == nil { - ui.Log(ui.AppLogger, "config.deleted", - "name", key, - "path", fileName) + ui.Log(ui.AppLogger, "config.deleted", ui.A{ + "name": key, + "path": fileName}) } else { - ui.Log(ui.AppLogger, "config.external.delete.error", - "path", fileName, - "error", err) + ui.Log(ui.AppLogger, "config.external.delete.error", ui.A{ + "path": fileName, + "error": err}) } } } // If the deletion was successful, log the deletion. if err == nil { - ui.Log(ui.AppLogger, "config.deleted", - "name", key, - "path", path) + ui.Log(ui.AppLogger, "config.deleted", ui.A{ + "name": key, + "path": path}) } return err } - ui.Log(ui.AppLogger, "config.delete.not.found", - "name", key) + ui.Log(ui.AppLogger, "config.delete.not.found", ui.A{ + "name": key}) return errors.ErrNoSuchProfile.Context(key) } diff --git a/app-cli/settings/values.go b/app-cli/settings/values.go index 95732c89..b8412d80 100644 --- a/app-cli/settings/values.go +++ b/app-cli/settings/values.go @@ -30,7 +30,9 @@ func Set(key string, value string) { c.Modified = time.Now().Format(time.RFC1123Z) c.Dirty = true - ui.Log(ui.AppLogger, "config.set", "name", key, "value", value) + ui.Log(ui.AppLogger, "config.set", ui.A{ + "name": key, + "value": value}) } // SetDefault puts a profile entry in the current Configuration structure. It is @@ -39,9 +41,9 @@ func Set(key string, value string) { func SetDefault(key string, value string) { explicitValues.Items[key] = value - ui.Log(ui.AppLogger, "config.set.default", - "name", key, - "value", value) + ui.Log(ui.AppLogger, "config.set.default", ui.A{ + "name": key, + "value": value}) } // ClearDefaults clears all emphemeral (default) keys from the explicit values map. @@ -132,8 +134,8 @@ func Delete(key string) error { delete(c.Items, key) } - ui.Log(ui.AppLogger, "config.deleting", - "name", key) + ui.Log(ui.AppLogger, "config.deleting", ui.A{ + "name": key}) return nil } diff --git a/app-cli/ui/logfile.go b/app-cli/ui/logfile.go index 5e9130f4..807d3a84 100644 --- a/app-cli/ui/logfile.go +++ b/app-cli/ui/logfile.go @@ -96,7 +96,7 @@ func openLogFile(path string, withTimeStamp bool) error { baseLogFileName, _ = filepath.Abs(path) currentLogFileName, _ = filepath.Abs(fileName) - WriteLog(ServerLogger, "logging.filename", "name", currentLogFileName) + WriteLog(InfoLogger, "logging.filename", "name", currentLogFileName) return nil } @@ -119,7 +119,7 @@ func rollOverTask() { count++ - WriteLog(ServerLogger, "logging.rollover.scheduled", "count", count, "time", wakeTime.String()) + WriteLog(InfoLogger, "logging.rollover.scheduled", "count", count, "time", wakeTime.String()) time.Sleep(sleepUntil) RollOverLog() } @@ -135,7 +135,7 @@ func RollOverLog() { } if err := openLogFile(baseLogFileName, true); err != nil { - WriteLog(InternalLogger, "logging.rollover.open", "error", err) + WriteLog(InfoLogger, "logging.rollover.open", "error", err) return } @@ -179,12 +179,12 @@ func PurgeLogs() int { logmsg = "logging.archiving" } - Log(ServerLogger, logmsg, "count", keep, "path", searchPath) + Log(InfoLogger, logmsg, "count", keep, "path", searchPath) // Start by making a list of the log files in the directory. files, err := os.ReadDir(searchPath) if err != nil { - Log(ServerLogger, "logging.list.error", "error", err.Error()) + Log(InfoLogger, "logging.list.error", "error", err.Error()) return count } @@ -208,12 +208,12 @@ func PurgeLogs() int { // If we're archving, add this log file to the archive before we delete it. if archiveLogFileName != "" { if err := addToLogArchive(fileName); err != nil { - Log(ServerLogger, "logging.archive.error", "error", err) + Log(InfoLogger, "logging.archive.error", "error", err) } else { - Log(ServerLogger, "logging.archived", "filename", fileName) + Log(InfoLogger, "logging.archived", "filename", fileName) if err := os.Remove(fileName); err != nil { - Log(ServerLogger, "logging.archive.delete.error", "error", err) + Log(InfoLogger, "logging.archive.delete.error", "error", err) } count++ @@ -224,9 +224,9 @@ func PurgeLogs() int { // Now delete the file being purged. if err := os.Remove(fileName); err != nil { - Log(ServerLogger, "logging.purge.error", "error", err) + Log(InfoLogger, "logging.purge.error", "error", err) } else { - Log(ServerLogger, "logging.purged", "filename", fileName) + Log(InfoLogger, "logging.purged", "filename", fileName) count++ } diff --git a/commands/server.go b/commands/server.go index 16687af7..a25f73c1 100644 --- a/commands/server.go +++ b/commands/server.go @@ -345,8 +345,8 @@ func setServerDefaults(c *cli.Context) (string, string, error) { defs.InstanceID, found = c.String("session-uuid") if found { symbols.RootSymbolTable.SetAlways(defs.InstanceUUIDVariable, defs.InstanceID) - ui.Log(ui.AppLogger, "server.explicit.id", - "id", defs.InstanceID) + ui.Log(ui.AppLogger, "server.explicit.id", ui.A{ + "id": defs.InstanceID}) } else { s, _ := symbols.RootSymbolTable.Get(defs.InstanceUUIDVariable) defs.InstanceID = data.String(s) @@ -552,12 +552,12 @@ func setupPath(c *cli.Context) { } // Dump the active configuration to the log. This is used during server startup -// when the INFO log is enabled. +// when the DEBIG log is enabled. func dumpConfigToLog() { - if ui.IsActive(ui.InfoLogger) { + if ui.IsActive(ui.DebugLogger) { keys := settings.Keys() if len(keys) > 0 { - ui.Log(ui.InfoLogger, "server.active.config", + ui.Log(ui.ServerLogger, "server.active.config", "profile", settings.ActiveProfileName()) for _, key := range keys { @@ -565,7 +565,7 @@ func dumpConfigToLog() { continue } - ui.Log(ui.InfoLogger, "server.config.item", + ui.Log(ui.ServerLogger, "server.config.item", "key", key, "value", settings.Get(key)) } diff --git a/tools/buildver.txt b/tools/buildver.txt index 4135c42d..f741f459 100644 --- a/tools/buildver.txt +++ b/tools/buildver.txt @@ -1 +1 @@ -1.5-1209 +1.5-1210