Improve client logging.
Some checks failed
Linting and tests / Linting (push) Failing after 4s
Linting and tests / Tests (push) Failing after 3s

This commit is contained in:
2025-09-10 20:04:19 +05:00
parent e3b9c9ae40
commit c2142cc1a6
15 changed files with 118 additions and 44 deletions

View File

@@ -3,7 +3,6 @@ package translations
import (
"encoding/json"
"fmt"
"log/slog"
"path/filepath"
"strings"
@@ -30,7 +29,7 @@ func (t *translations) sysInfoHandlerTranslationsLanguagesAndStringsCount() stri
entries, err := langfiles.LangFiles.ReadDir("files")
if err != nil {
slog.Error("Failed to read translations filesystem entries.", "error", err.Error())
t.logger.Error("Failed to read translations filesystem entries.", "error", err.Error())
return langString
}
@@ -43,7 +42,7 @@ func (t *translations) sysInfoHandlerTranslationsLanguagesAndStringsCount() stri
if strings.HasSuffix(entry.Name(), ".json") {
fileData, err := langfiles.LangFiles.ReadFile(filepath.Join("files", entry.Name()))
if err != nil {
slog.Error("Failed to read translation file!", "file", entry.Name(), "error", err.Error())
t.logger.Error("Failed to read translation file!", "file", entry.Name(), "error", err.Error())
return langString
}
@@ -51,7 +50,7 @@ func (t *translations) sysInfoHandlerTranslationsLanguagesAndStringsCount() stri
data := make(map[string]string)
if err := json.Unmarshal(fileData, &data); err != nil {
slog.Error("Failed to unmarshal translation file!", "file", entry.Name(), "error", err.Error())
t.logger.Error("Failed to unmarshal translation file!", "file", entry.Name(), "error", err.Error())
return langString
}

View File

@@ -16,6 +16,7 @@ var _ = core.Translations(&translations{})
type translations struct {
app *application.Application
logger *slog.Logger
mainWindow core.MainWindow
}
@@ -57,9 +58,13 @@ func (t *translations) ConnectDependencies() error {
}
func (t *translations) Initialize() error {
t.logger = t.app.NewLogger("service", core.ServiceNameTranslations)
t.logger.Info("Initializing...")
langFromEnv, _ := os.LookupEnv("LANG")
slog.Info("Current system locale.", "locale", lang.SystemLocale().String(), "LANG", langFromEnv)
t.logger.Info("Current system locale.", "locale", lang.SystemLocale().String(), "LANG", langFromEnv)
if err := lang.AddTranslationsFS(langfiles.LangFiles, "files"); err != nil {
return fmt.Errorf("%w: load translations: %w", core.ErrTranslations, err)