diff --git a/backend/args.go b/backend/args.go index 176ce9f2..8d79e51b 100644 --- a/backend/args.go +++ b/backend/args.go @@ -1,11 +1,11 @@ package backend import ( + "log/slog" "net/url" "strings" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/SatisfactoryModManager/backend/bindings" ) @@ -18,12 +18,12 @@ func ProcessArguments(args []string) { uri := args[0] err := handleURI(uri) if err != nil { - log.Error().Err(err).Str("uri", uri).Msg("Failed to handle smmanager:// URI") + slog.Error("failed to handle smmanager:// URI", slog.Any("error", err), slog.String("uri", uri)) } } else { err := handleFile(args[0]) if err != nil { - log.Error().Err(err).Str("path", args[1]).Msg("Failed to handle file") + slog.Error("failed to handle file", slog.Any("error", err), slog.String("path", args[0])) } } bindings.BindingsInstance.App.Show() diff --git a/backend/autoupdate/autoupdate.go b/backend/autoupdate/autoupdate.go index 23358990..14f35623 100644 --- a/backend/autoupdate/autoupdate.go +++ b/backend/autoupdate/autoupdate.go @@ -1,9 +1,9 @@ package autoupdate import ( + "log/slog" "time" - "github.com/rs/zerolog/log" "github.com/spf13/viper" "github.com/satisfactorymodding/SatisfactoryModManager/backend/autoupdate/updater" @@ -40,12 +40,12 @@ func CheckInterval(interval time.Duration) { go func() { err := Updater.CheckForUpdate() if err != nil { - log.Error().Err(err).Msg("Failed to check for update") + slog.Error("failed to check for update", slog.Any("error", err)) } for range updateCheckTicker.C { err := Updater.CheckForUpdate() if err != nil { - log.Error().Err(err).Msg("Failed to check for update") + slog.Error("failed to check for update", slog.Any("error", err)) } } }() diff --git a/backend/bindings/app.go b/backend/bindings/app.go index 7e814265..ce27785f 100644 --- a/backend/bindings/app.go +++ b/backend/bindings/app.go @@ -2,11 +2,11 @@ package bindings import ( "context" + "log/slog" "strings" "time" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/spf13/viper" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" @@ -76,7 +76,7 @@ func (a *App) startup(ctx context.Context) { if changed { err := settings.SaveSettings() if err != nil { - log.Error().Err(err).Msg("Failed to save settings") + slog.Error("failed to save settings", slog.Any("error", err)) } } } diff --git a/backend/bindings/debug_info.go b/backend/bindings/debug_info.go index 533580f8..68873d80 100644 --- a/backend/bindings/debug_info.go +++ b/backend/bindings/debug_info.go @@ -5,13 +5,13 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "os" "path" "runtime" "time" "github.com/pkg/errors" - "github.com/rs/zerolog/log" ficsitCli "github.com/satisfactorymodding/ficsit-cli/cli" "github.com/spf13/viper" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" @@ -175,7 +175,7 @@ func (d *DebugInfo) GenerateDebugInfo() bool { }, }) if err != nil { - log.Error().Err(err).Msg("Failed to open save dialog") + slog.Error("failed to open save dialog", slog.Any("error", err)) return false } if filename == "" { @@ -184,7 +184,7 @@ func (d *DebugInfo) GenerateDebugInfo() bool { err = d.generateAndSaveDebugInfo(filename) if err != nil { - log.Error().Err(err).Msg("Failed to generate debuginfo") + slog.Error("failed to generate debug info", slog.Any("error", err)) return false } diff --git a/backend/bindings/ficsitcli/installs.go b/backend/bindings/ficsitcli/installs.go index 9bf4eaba..813d5515 100644 --- a/backend/bindings/ficsitcli/installs.go +++ b/backend/bindings/ficsitcli/installs.go @@ -1,13 +1,14 @@ package ficsitcli import ( + "log/slog" "os" "os/exec" "sort" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/ficsit-cli/cli" + resolver "github.com/satisfactorymodding/ficsit-resolver" "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders" ) @@ -133,13 +134,13 @@ func (f *FicsitCLI) GetInstallation(path string) *InstallationInfo { } func (f *FicsitCLI) SelectInstall(path string) error { - l := log.With().Str("task", "selectInstall").Str("path", path).Logger() + l := slog.With(slog.String("task", "selectInstall"), slog.String("path", path)) if f.selectedInstallation != nil && f.selectedInstallation.Info.Path == path { return nil } installation := f.GetInstallation(path) if installation == nil { - l.Error().Str("path", path).Msg("Failed to find installation") + l.Error("Failed to find installation") return errors.New("Installation \"" + path + "\" not found") } f.selectedInstallation = installation @@ -162,7 +163,7 @@ func (f *FicsitCLI) SelectInstall(path string) error { installErr := f.validateInstall(f.selectedInstallation, "__select_install__") if installErr != nil { - l.Error().Err(installErr).Str("install", installation.Info.Path).Msg("Failed to validate install") + l.Error("Failed to validate install", slog.Any("error", installErr), slog.String("install", installation.Info.Path)) return errors.Wrap(installErr, "Failed to validate install") } return nil @@ -177,10 +178,10 @@ func (f *FicsitCLI) GetSelectedInstall() *installfinders.Installation { func (f *FicsitCLI) SetModsEnabled(enabled bool) error { if f.selectedInstallation == nil { - log.Error().Msg("No installation selected") + slog.Error("no installation selected") return errors.New("No installation selected") } - l := log.With().Str("task", "setModsEnabled").Bool("enabled", enabled).Logger() + l := slog.With(slog.String("task", "setModsEnabled"), slog.Bool("enabled", enabled), slog.String("install", f.selectedInstallation.Info.Path)) var message string if enabled { @@ -207,7 +208,7 @@ func (f *FicsitCLI) SetModsEnabled(enabled bool) error { installErr := f.validateInstall(f.selectedInstallation, "__toggle_mods__") if installErr != nil { - l.Error().Err(installErr).Str("install", f.selectedInstallation.Info.Path).Msg("Failed to validate install") + l.Error("failed to validate install", slog.Any("error", installErr)) return errors.Wrap(installErr, "Failed to validate install") } @@ -226,21 +227,21 @@ func (f *FicsitCLI) GetSelectedInstallProfileMods() map[string]cli.ProfileMod { return profile.Mods } -func (f *FicsitCLI) GetSelectedInstallLockfileMods() (map[string]cli.LockedMod, error) { +func (f *FicsitCLI) GetSelectedInstallLockfileMods() (map[string]resolver.LockedMod, error) { if f.selectedInstallation == nil { - return make(map[string]cli.LockedMod), nil + return make(map[string]resolver.LockedMod), nil } lockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli) if err != nil { return nil, errors.Wrap(err, "failed to get lockfile") } if lockfile == nil { - return make(map[string]cli.LockedMod), nil + return make(map[string]resolver.LockedMod), nil } return lockfile.Mods, nil } -func (f *FicsitCLI) GetSelectedInstallLockfile() (*cli.LockFile, error) { +func (f *FicsitCLI) GetSelectedInstallLockfile() (*resolver.LockFile, error) { if f.selectedInstallation == nil { return nil, nil } @@ -253,13 +254,13 @@ func (f *FicsitCLI) GetSelectedInstallLockfile() (*cli.LockFile, error) { func (f *FicsitCLI) LaunchGame() { if f.selectedInstallation == nil { - log.Error().Msg("No installation selected") + slog.Error("no installation selected") return } cmd := exec.Command(f.selectedInstallation.Info.LaunchPath[0], f.selectedInstallation.Info.LaunchPath[1:]...) out, err := cmd.CombinedOutput() if err != nil { - log.Error().Err(err).Str("cmd", cmd.String()).Str("output", string(out)).Msg("Failed to launch game") + slog.Error("failed to launch game", slog.Any("error", err), slog.String("cmd", cmd.String()), slog.String("output", string(out))) return } } diff --git a/backend/bindings/ficsitcli/process.go b/backend/bindings/ficsitcli/process.go index 5ae5f06b..2ed1247a 100644 --- a/backend/bindings/ficsitcli/process.go +++ b/backend/bindings/ficsitcli/process.go @@ -2,11 +2,11 @@ package ficsitcli import ( "fmt" + "log/slog" "sync" "time" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/ficsit-cli/cli" "github.com/satisfactorymodding/ficsit-cli/utils" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" @@ -124,7 +124,7 @@ func (f *FicsitCLI) validateInstall(installation *InstallationInfo, progressItem func (f *FicsitCLI) EmitModsChange() { lockfileMods, err := f.GetSelectedInstallLockfileMods() if err != nil { - log.Error().Err(err).Msg("Failed to load lockfile") + slog.Error("failed to load lockfile", slog.Any("error", err)) return } wailsRuntime.EventsEmit(f.ctx, "lockfileMods", lockfileMods) diff --git a/backend/bindings/ficsitcli/profiles.go b/backend/bindings/ficsitcli/profiles.go index 1888393c..532ad006 100644 --- a/backend/bindings/ficsitcli/profiles.go +++ b/backend/bindings/ficsitcli/profiles.go @@ -3,21 +3,22 @@ package ficsitcli import ( "encoding/json" "fmt" + "log/slog" "os" "sort" "time" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/ficsit-cli/cli" + resolver "github.com/satisfactorymodding/ficsit-resolver" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" ) func (f *FicsitCLI) SetProfile(profile string) error { - l := log.With().Str("task", "setProfile").Str("profile", profile).Logger() + l := slog.With(slog.String("task", "setProfile"), slog.String("profile", profile)) if f.selectedInstallation == nil { - l.Error().Str("profile", profile).Msg("No installation selected") + l.Error("no installation selected") return errors.New("No installation selected") } if f.selectedInstallation.Installation.Profile == profile { @@ -25,7 +26,7 @@ func (f *FicsitCLI) SetProfile(profile string) error { } err := f.selectedInstallation.Installation.SetProfile(f.ficsitCli, profile) if err != nil { - l.Error().Err(err).Str("profile", profile).Msg("Failed to set profile") + l.Error("failed to set profile", slog.Any("error", err)) return errors.Wrap(err, "Failed to set profile") } _ = f.ficsitCli.Installations.Save() @@ -45,7 +46,7 @@ func (f *FicsitCLI) SetProfile(profile string) error { installErr := f.validateInstall(f.selectedInstallation, "__select_profile__") if installErr != nil { - l.Error().Err(installErr).Str("profile", profile).Msg("Failed to validate install") + l.Error("failed to validate installation", slog.Any("error", installErr)) return errors.Wrap(installErr, "Failed to validate install") } @@ -73,11 +74,11 @@ func (f *FicsitCLI) GetProfile(profile string) *cli.Profile { } func (f *FicsitCLI) AddProfile(name string) error { - l := log.With().Str("task", "addProfile").Str("profile", name).Logger() + l := slog.With(slog.String("task", "addProfile"), slog.String("profile", name)) _, err := f.ficsitCli.Profiles.AddProfile(name) if err != nil { - l.Error().Err(err).Str("name", name).Msg("Failed to add profile") + l.Error("failed to add profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to add profile: %s", name) } @@ -89,11 +90,11 @@ func (f *FicsitCLI) AddProfile(name string) error { } func (f *FicsitCLI) RenameProfile(oldName string, newName string) error { - l := log.With().Str("task", "renameProfile").Str("oldName", oldName).Str("newName", newName).Logger() + l := slog.With(slog.String("task", "renameProfile"), slog.String("oldName", oldName), slog.String("newName", newName)) err := f.ficsitCli.Profiles.RenameProfile(f.ficsitCli, oldName, newName) if err != nil { - l.Error().Err(err).Str("oldName", oldName).Str("newName", newName).Msg("Failed to rename profile") + l.Error("failed to rename profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to rename profile: %s -> %s", oldName, newName) } @@ -105,11 +106,11 @@ func (f *FicsitCLI) RenameProfile(oldName string, newName string) error { } func (f *FicsitCLI) DeleteProfile(name string) error { - l := log.With().Str("task", "deleteProfile").Str("profile", name).Logger() + l := slog.With(slog.String("task", "deleteProfile"), slog.String("profile", name)) err := f.ficsitCli.Profiles.DeleteProfile(name) if err != nil { - l.Error().Err(err).Str("name", name).Msg("Failed to delete profile") + l.Error("failed to delete profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to delete profile: %s", name) } @@ -128,7 +129,7 @@ func (f *FicsitCLI) DeleteProfile(name string) error { type ExportedProfile struct { Profile cli.Profile `json:"profile"` - LockFile cli.LockFile `json:"lockfile"` + LockFile resolver.LockFile `json:"lockfile"` Metadata *ExportedProfileMetadata `json:"metadata"` } @@ -137,27 +138,27 @@ type ExportedProfileMetadata struct { } func (f *FicsitCLI) MakeCurrentExportedProfile() (*ExportedProfile, error) { - l := log.With().Str("task", "makeCurrentExportedProfile").Logger() + l := slog.With(slog.String("task", "makeCurrentExportedProfile")) if f.selectedInstallation == nil { - l.Error().Msg("No installation selected") + l.Error("no installation selected") return nil, errors.New("No installation selected") } profileName := f.GetSelectedProfile() if profileName == nil { - l.Error().Msg("No profile selected") + l.Error("no profile selected") return nil, errors.New("No profile selected") } profile := f.GetProfile(*profileName) if profile == nil { - l.Error().Str("profile", *profileName).Msg("Profile not found") + l.Error("profile not found", slog.String("profile", *profileName)) return nil, errors.New("Profile not found") } lockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli) if err != nil { - l.Error().Err(err).Msg("Failed to get lockfile") + l.Error("failed to get lockfile", slog.Any("error", err)) return nil, errors.Wrap(err, "Failed to get lockfile") } metadata := &ExportedProfileMetadata{ @@ -165,7 +166,7 @@ func (f *FicsitCLI) MakeCurrentExportedProfile() (*ExportedProfile, error) { } if lockfile == nil { - lockfile = cli.MakeLockfile() + lockfile = resolver.NewLockfile() } return &ExportedProfile{ @@ -176,11 +177,11 @@ func (f *FicsitCLI) MakeCurrentExportedProfile() (*ExportedProfile, error) { } func (f *FicsitCLI) ExportCurrentProfile() error { - l := log.With().Str("task", "exportCurrentProfile").Logger() + l := slog.With(slog.String("task", "exportCurrentProfile")) exportedProfile, err := f.MakeCurrentExportedProfile() if err != nil { - l.Error().Err(err).Msg("Failed to make exported profile") + l.Error("failed to make exported profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to export profile") } @@ -195,18 +196,18 @@ func (f *FicsitCLI) ExportCurrentProfile() error { }, }) if err != nil { - l.Error().Err(err).Msg("Failed to open save dialog") + l.Error("failed to open save dialog", slog.Any("error", err)) return errors.Wrapf(err, "Failed to export profile: %s", exportedProfile.Profile.Name) } exportedProfileJSON, err := json.MarshalIndent(exportedProfile, "", " ") if err != nil { - l.Error().Err(err).Msg("Failed to marshal exported profile") + l.Error("failed to marshal exported profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to export profile: %s", exportedProfile.Profile.Name) } err = os.WriteFile(filename, exportedProfileJSON, 0o755) if err != nil { - l.Error().Err(err).Msg("Failed to write exported profile") + l.Error("failed to write exported profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to export profile: %s", exportedProfile.Profile.Name) } @@ -214,18 +215,18 @@ func (f *FicsitCLI) ExportCurrentProfile() error { } func (f *FicsitCLI) ReadExportedProfileMetadata(file string) (*ExportedProfileMetadata, error) { - l := log.With().Str("task", "readExportedProfileMetadata").Str("file", file).Logger() + l := slog.With(slog.String("task", "readExportedProfileMetadata"), slog.String("file", file)) fileBytes, err := os.ReadFile(file) if err != nil { - l.Error().Err(err).Str("file", file).Msg("Failed to read exported profile") + l.Error("failed to read exported profile", slog.Any("error", err)) return nil, errors.Wrap(err, "Failed to read exported profile") } var exportedProfile ExportedProfile err = json.Unmarshal(fileBytes, &exportedProfile) if err != nil { - l.Error().Err(err).Str("file", file).Msg("Failed to unmarshal exported profile") + l.Error("failed to unmarshal exported profile", slog.Any("error", err)) return nil, errors.Wrap(err, "Failed to read exported profile") } @@ -233,29 +234,29 @@ func (f *FicsitCLI) ReadExportedProfileMetadata(file string) (*ExportedProfileMe } func (f *FicsitCLI) ImportProfile(name string, file string) error { - l := log.With().Str("task", "importProfile").Str("name", name).Str("file", file).Logger() + l := slog.With(slog.String("task", "importProfile"), slog.String("name", name), slog.String("file", file)) if f.selectedInstallation == nil { - l.Error().Msg("No installation selected") + l.Error("no installation selected") return errors.New("No installation selected") } profileData, err := os.ReadFile(file) if err != nil { - l.Error().Err(err).Str("file", file).Msg("Failed to read exported profile") + l.Error("failed to read exported profile", slog.Any("error", err)) return errors.Wrap(err, "Failed to read profile file") } var exportedProfile ExportedProfile err = json.Unmarshal(profileData, &exportedProfile) if err != nil { - l.Error().Err(err).Str("file", file).Msg("Failed to unmarshal exported profile") + l.Error("failed to unmarshal exported profile", slog.Any("error", err)) return errors.Wrap(err, "Failed to read profile file") } profile, err := f.ficsitCli.Profiles.AddProfile(name) if err != nil { - l.Error().Err(err).Str("name", name).Msg("Failed to add profile") + l.Error("failed to add profile", slog.Any("error", err)) return errors.Wrap(err, "Failed to add imported profile") } @@ -266,7 +267,7 @@ func (f *FicsitCLI) ImportProfile(name string, file string) error { err = f.selectedInstallation.Installation.WriteLockFile(f.ficsitCli, &exportedProfile.LockFile) if err != nil { _ = f.ficsitCli.Profiles.DeleteProfile(name) - l.Error().Err(err).Str("name", name).Msg("Failed to write lockfile") + l.Error("failed to write lockfile", slog.Any("error", err)) return errors.Wrap(err, "Failed to write profile") } @@ -286,7 +287,7 @@ func (f *FicsitCLI) ImportProfile(name string, file string) error { if installErr != nil { _ = f.ficsitCli.Profiles.DeleteProfile(name) - l.Error().Err(installErr).Str("profile", name).Msg("Failed to validate install") + l.Error("failed to validate installation", slog.Any("error", installErr)) return errors.Wrap(installErr, "Failed to validate install") } diff --git a/backend/bindings/ficsitcli/update.go b/backend/bindings/ficsitcli/update.go index 516a5ecc..97712ac4 100644 --- a/backend/bindings/ficsitcli/update.go +++ b/backend/bindings/ficsitcli/update.go @@ -1,9 +1,12 @@ package ficsitcli import ( + "log/slog" + "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/ficsit-cli/cli" + resolver "github.com/satisfactorymodding/ficsit-resolver" + "github.com/spf13/viper" ) type Update struct { @@ -16,11 +19,11 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) { if f.selectedInstallation == nil { return []Update{}, nil } - l := log.With().Str("task", "checkForUpdates").Logger() + l := slog.With(slog.String("task", "checkForUpdates")) currentLockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli) if err != nil { - l.Error().Err(err).Msg("Failed to get current lockfile") + l.Error("failed to get current lockfile", slog.Any("error", err)) return nil, errors.Wrap(err, "Failed to get current lockfile") } @@ -30,11 +33,11 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) { profile := f.GetProfile(f.selectedInstallation.Installation.Profile) - resolver := cli.NewDependencyResolver(f.ficsitCli.Provider) + resolver := resolver.NewDependencyResolver(f.ficsitCli.Provider, viper.GetString("api-base")) gameVersion, err := f.selectedInstallation.Installation.GetGameVersion(f.ficsitCli) if err != nil { - l.Error().Err(err).Msg("Failed to get game version") + l.Error("failed to get game version", slog.Any("error", err)) return nil, errors.Wrap(err, "Failed to get game version") } @@ -50,7 +53,7 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) { } newLockfile, err := updateProfile.Resolve(resolver, nil, gameVersion) if err != nil { - l.Error().Err(err).Msg("Failed to resolve new lockfile") + l.Error("failed to resolve dependencies", slog.Any("error", err)) return nil, errors.Wrap(err, "Error resolving dependencies") } @@ -72,10 +75,10 @@ func (f *FicsitCLI) CheckForUpdates() ([]Update, error) { } func (f *FicsitCLI) UpdateMods(mods []string) error { - l := log.With().Str("task", "updateAllMods").Logger() + l := slog.With(slog.String("task", "updateMods")) if f.progress != nil { - l.Error().Msg("Another operation in progress") + l.Error("another operation in progress") return errors.New("Another operation in progress") } @@ -86,7 +89,7 @@ func (f *FicsitCLI) UpdateMods(mods []string) error { profile := f.GetProfile(f.selectedInstallation.Installation.Profile) for _, modReference := range mods { if _, ok := profile.Mods[modReference]; !ok { - l.Warn().Str("mod", modReference).Msg("Mod not found in profile") + l.Warn("mod not found in profile", slog.String("mod", modReference)) continue } profile.Mods[modReference] = cli.ProfileMod{ @@ -97,7 +100,7 @@ func (f *FicsitCLI) UpdateMods(mods []string) error { err := f.selectedInstallation.Installation.UpdateMods(f.ficsitCli, mods) if err != nil { - l.Error().Err(err).Msg("Failed to update mods") + l.Error("failed to update mods", slog.Any("error", err)) return errors.Wrap(err, "Failed to update mods") } @@ -114,7 +117,7 @@ func (f *FicsitCLI) UpdateMods(mods []string) error { err = f.validateInstall(f.selectedInstallation, "__update__") if err != nil { - l.Error().Err(err).Msg("Failed to validate installation") + l.Error("failed to validate installation", slog.Any("error", err)) return errors.Wrap(err, "Failed to validate installation") } diff --git a/backend/bindings/ficsitcli/wrapper.go b/backend/bindings/ficsitcli/wrapper.go index 54000a58..de8600b3 100644 --- a/backend/bindings/ficsitcli/wrapper.go +++ b/backend/bindings/ficsitcli/wrapper.go @@ -2,11 +2,11 @@ package ficsitcli import ( "context" + "log/slog" "time" "github.com/mitchellh/go-ps" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "github.com/satisfactorymodding/ficsit-cli/cli" "github.com/satisfactorymodding/ficsit-cli/cli/provider" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" @@ -56,7 +56,7 @@ func (f *FicsitCLI) Init() error { for range gameRunningTicker.C { processes, err := ps.Processes() if err != nil { - log.Error().Err(err).Msg("failed to get processes") + slog.Error("failed to get processes", slog.Any("error", err)) continue } f.isGameRunning = false diff --git a/backend/wails_logger.go b/backend/wails_logger.go index ac8cdb72..daba0a55 100644 --- a/backend/wails_logger.go +++ b/backend/wails_logger.go @@ -1,33 +1,37 @@ package backend -import "github.com/rs/zerolog/log" +import ( + "log/slog" + "os" +) type WailsZeroLogLogger struct{} func (l WailsZeroLogLogger) Print(message string) { - log.Trace().Msg(message) + slog.Debug(message) } func (l WailsZeroLogLogger) Trace(message string) { - log.Trace().Msg(message) + slog.Debug(message) } func (l WailsZeroLogLogger) Debug(message string) { - log.Debug().Msg(message) + slog.Debug(message) } func (l WailsZeroLogLogger) Info(message string) { - log.Info().Msg(message) + slog.Info(message) } func (l WailsZeroLogLogger) Warning(message string) { - log.Warn().Msg(message) + slog.Warn(message) } func (l WailsZeroLogLogger) Error(message string) { - log.Error().Msg(message) + slog.Error(message) } func (l WailsZeroLogLogger) Fatal(message string) { - log.Fatal().Msg(message) + slog.Error(message) + os.Exit(1) } diff --git a/backend/websocket/websocket.go b/backend/websocket/websocket.go index f8c032c4..eead4e64 100644 --- a/backend/websocket/websocket.go +++ b/backend/websocket/websocket.go @@ -3,7 +3,8 @@ package websocket import ( - "github.com/rs/zerolog/log" + "log/slog" + "github.com/spf13/viper" engineio_types "github.com/zishang520/engine.io/types" "github.com/zishang520/socket.io/socket" @@ -25,11 +26,11 @@ func ListenAndServeWebsocket() { _ = client.On("installedMods", func(datas ...any) { lockfile, err := bindings.BindingsInstance.FicsitCLI.GetSelectedInstallLockfile() if err != nil { - log.Error().Err(err).Msg("Failed to get lockfile") + slog.Error("failed to get lockfile", slog.Any("error", err)) return } if lockfile == nil { - log.Error().Err(err).Msg("no lockfile found for websocket call") + slog.Error("no lockfile found for websocket call", slog.Any("error", err)) return } installedMods := make(map[string]string) diff --git a/go.mod b/go.mod index 0c9df5ab..6d91e3f4 100644 --- a/go.mod +++ b/go.mod @@ -7,22 +7,22 @@ toolchain go1.21.5 require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/andygrunwald/vdf v1.1.0 + github.com/lmittmann/tint v1.0.3 github.com/minio/selfupdate v0.6.0 github.com/mitchellh/go-ps v1.0.0 github.com/pkg/errors v0.9.1 - github.com/rs/zerolog v1.31.0 - github.com/satisfactorymodding/ficsit-cli v0.2.0 - github.com/spf13/viper v1.18.0 + github.com/samber/slog-multi v1.0.2 + github.com/satisfactorymodding/ficsit-cli v0.3.0 + github.com/satisfactorymodding/ficsit-resolver v0.0.2 + github.com/spf13/viper v1.18.1 github.com/wailsapp/wails/v2 v2.7.1 github.com/zishang520/engine.io v1.5.12 github.com/zishang520/socket.io v1.3.2 - golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb + golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 golang.org/x/sys v0.15.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) -replace github.com/Masterminds/semver/v3 => github.com/Vilsol/semver/v3 v3.1.2-0.20220414201711-64ef71d40f9a - require ( aead.dev/minisign v0.2.1 // indirect github.com/Khan/genqlient v0.6.0 // indirect @@ -50,8 +50,9 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mircearoata/pubgrub-go v0.3.3 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + github.com/pterm/pterm v0.12.72 // indirect github.com/puzpuzpuz/xsync/v3 v3.0.2 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect diff --git a/go.sum b/go.sum index 3b1137a8..d04ab169 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk= github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM= github.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4= github.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY= -github.com/Vilsol/semver/v3 v3.1.2-0.20220414201711-64ef71d40f9a h1:Z443bc6RS9J5qRi7KGqWpStbNYxhDWtSqK/mPQNsIO4= -github.com/Vilsol/semver/v3 v3.1.2-0.20220414201711-64ef71d40f9a/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI= @@ -25,7 +25,6 @@ github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY= github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -36,7 +35,6 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= @@ -81,6 +79,8 @@ github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI= github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= +github.com/lmittmann/tint v1.0.3 h1:W5PHeA2D8bBJVvabNfQD/XW9HPLZK1XoPZH0cq8NouQ= +github.com/lmittmann/tint v1.0.3/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= @@ -88,7 +88,6 @@ github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwM github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= @@ -101,8 +100,8 @@ github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -110,8 +109,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pterm/pterm v0.12.71 h1:KcEJ98EiVCbzDkFbktJ2gMlr4pn8IzyGb9bwK6ffkuA= -github.com/pterm/pterm v0.12.71/go.mod h1:SUAcoZjRt+yjPWlWba+/Fd8zJJ2lSXBQWf0Z0HbFiIQ= +github.com/pterm/pterm v0.12.72 h1:1W7Oqi5yjEvrI0QroBqUefqXKJW4aD8/wAuqqd5qj0Q= +github.com/pterm/pterm v0.12.72/go.mod h1:+M33aZWQVpmLmLbvjykyGZ4gAfeebznRo8JMbabaxQU= github.com/puzpuzpuz/xsync/v3 v3.0.2 h1:3yESHrRFYr6xzkz61LLkvNiPFXxJEAABanTQpKbAaew= github.com/puzpuzpuz/xsync/v3 v3.0.2/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -119,17 +118,18 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= -github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= -github.com/satisfactorymodding/ficsit-cli v0.2.0 h1:5sC4YgqGCDeIqZ0B9jrwnDxIPbIEmnGdph7+aqm9Cz4= -github.com/satisfactorymodding/ficsit-cli v0.2.0/go.mod h1:CDKrUreJ5m63sb4BcunHkUBJtD2xcAlXxfcoj/CPM0s= +github.com/samber/slog-multi v1.0.2 h1:6BVH9uHGAsiGkbbtQgAOQJMpKgV8unMrHhhJaw+X1EQ= +github.com/samber/slog-multi v1.0.2/go.mod h1:uLAvHpGqbYgX4FSL0p1ZwoLuveIAJvBECtE07XmYvFo= +github.com/satisfactorymodding/ficsit-cli v0.3.0 h1:5XeRNpvKpmob1rHmhx7arNSP3wnV0h19JSpzpV/nONQ= +github.com/satisfactorymodding/ficsit-cli v0.3.0/go.mod h1:mBk/SRGidCKi8xGXRbRxjh8vfYQn0zzjz+zCW6mr6Ho= +github.com/satisfactorymodding/ficsit-resolver v0.0.2 h1:dj/OsDLpaMUqCHpfBVHvDMUv2nf5gT4HS2ydBMkmtcQ= +github.com/satisfactorymodding/ficsit-resolver v0.0.2/go.mod h1:ckKMmMvDoYbbkEbWXEsMes608uvv6EKphXPhHX8LKSc= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= @@ -140,8 +140,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.0 h1:pN6W1ub/G4OfnM+NR9p7xP9R6TltLUzp5JG9yZD3Qg0= -github.com/spf13/viper v1.18.0/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= +github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM= +github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -186,8 +186,8 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4= +golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -206,7 +206,6 @@ golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= diff --git a/main.go b/main.go index 284265cd..f5f81e2a 100644 --- a/main.go +++ b/main.go @@ -4,16 +4,16 @@ import ( "context" "embed" "encoding/json" - "io" + "log/slog" "os" "path" "path/filepath" "runtime" "time" + "github.com/lmittmann/tint" "github.com/pkg/errors" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" + slogmulti "github.com/samber/slog-multi" "github.com/spf13/viper" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" @@ -56,12 +56,14 @@ func main() { err := settings.LoadSettings() if err != nil { - log.Fatal().Err(err).Msg("Failed to load settings") + slog.Error("failed to load settings", slog.Any("error", err)) + os.Exit(1) } b, err := bindings.MakeBindings() if err != nil { - log.Fatal().Err(err).Msg("Failed to create bindings") + slog.Error("failed to create bindings", slog.Any("error", err)) + os.Exit(1) } windowStartState := options.Normal @@ -101,12 +103,12 @@ func main() { }) if err != nil { - log.Error().Err(err).Msg("Failed to start application") + slog.Error("failed to start application", slog.Any("error", err)) } err = autoupdate.OnExit(bindings.BindingsInstance.Update.Restart) if err != nil { - log.Error().Err(err).Msg("Failed to apply update on exit") + slog.Error("failed to apply update on exit", slog.Any("error", err)) } } @@ -126,7 +128,8 @@ func init() { case "linux": baseLocalDir = path.Join(os.Getenv("HOME"), ".local", "share") default: - log.Fatal().Str("os", runtime.GOOS).Msg("Unsupported OS") + slog.Error("unsupported OS", slog.String("os", runtime.GOOS)) + os.Exit(1) } viper.Set("base-local-dir", baseLocalDir) @@ -140,6 +143,10 @@ func init() { _ = utils.EnsureDirExists(cacheDir) viper.Set("cache-dir", cacheDir) + smmCacheDir := filepath.Clean(filepath.Join(baseCacheDir, "SatisfactoryModManager")) + _ = utils.EnsureDirExists(smmCacheDir) + viper.Set("smm-cache-dir", smmCacheDir) + localDir := filepath.Clean(filepath.Join(baseLocalDir, "ficsit")) _ = utils.EnsureDirExists(localDir) viper.Set("local-dir", localDir) @@ -160,15 +167,19 @@ func init() { viper.Set("graphql-api", "/v2/query") viper.Set("log", "debug") - viper.Set("log-file", filepath.Join(cacheDir, "logs", "SatisfactoryModManager.log")) + viper.Set("log-file", filepath.Join(smmCacheDir, "logs", "SatisfactoryModManager.log")) viper.Set("concurrent-downloads", 5) - writers := make([]io.Writer, 0) - writers = append(writers, zerolog.ConsoleWriter{ - Out: os.Stdout, + level := slog.LevelInfo + _ = level.UnmarshalText([]byte(viper.GetString("log"))) + + handlers := make([]slog.Handler, 0) + handlers = append(handlers, tint.NewHandler(os.Stdout, &tint.Options{ + Level: level, + AddSource: true, TimeFormat: time.RFC3339, - }) + })) if viper.GetString("log-file") != "" { logFile := &lumberjack.Logger{ @@ -178,18 +189,8 @@ func init() { MaxAge: 30, // days } - writers = append(writers, zerolog.ConsoleWriter{ - Out: logFile, - TimeFormat: time.RFC3339, - NoColor: true, - }) - } - - level, err := zerolog.ParseLevel(viper.GetString("log")) - if err != nil { - panic(err) + handlers = append(handlers, slog.NewJSONHandler(logFile, nil)) } - zerolog.SetGlobalLevel(level) - log.Logger = zerolog.New(io.MultiWriter(writers...)).With().Timestamp().Logger() + slog.SetDefault(slog.New(slogmulti.Fanout(handlers...))) }