Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: tweak logger
Stevend11bd30ec634
diff --git a/server/profile/profile.go b/server/profile/profile.goindex 8afcefcef..e9a26b0b5 100644--- a/server/profile/profile.go+++ b/server/profile/profile.go@@ -2,6 +2,7 @@ package profileimport ("fmt"+ "log/slog""os""path/filepath""runtime"@@ -68,7 +69,7 @@ func (p *Profile) Validate() error {p.Data = filepath.Join(os.Getenv("ProgramData"), "memos")if _, err := os.Stat(p.Data); os.IsNotExist(err) {if err := os.MkdirAll(p.Data, 0770); err != nil {- fmt.Printf("Failed to create data directory: %s, err: %+v\n", p.Data, err)+ slog.Error("failed to create data directory", slog.String("data", p.Data), slog.String("error", err.Error()))return err}}@@ -79,7 +80,7 @@ func (p *Profile) Validate() error {dataDir, err := checkDataDir(p.Data)if err != nil {- fmt.Printf("Failed to check dsn: %s, err: %+v\n", dataDir, err)+ slog.Error("failed to check dsn", slog.String("data", dataDir), slog.String("error", err.Error()))return err}diff --git a/server/runner/version/runner.go b/server/runner/version/runner.goindex a2aff69e4..0dc0afed1 100644--- a/server/runner/version/runner.go+++ b/server/runner/version/runner.go@@ -5,11 +5,11 @@ import ("bytes""context""encoding/json"- "fmt""net/http""time""github.com/pkg/errors"+ "golang.org/x/exp/slog"storepb "github.com/usememos/memos/proto/gen/store""github.com/usememos/memos/server/profile"@@ -115,7 +115,7 @@ func (r *Runner) Check(ctx context.Context) {ActivityId: &activity.ID,},}); err != nil {- fmt.Printf("failed to create inbox: %s\n", err)+ slog.Error("failed to create inbox", slog.String("error", err.Error()))}}diff --git a/server/server.go b/server/server.goindex 211d13f21..6dd8b6912 100644--- a/server/server.go+++ b/server/server.go@@ -129,15 +129,15 @@ func (s *Server) Shutdown(ctx context.Context) {// Shutdown echo server.if err := s.echoServer.Shutdown(ctx); err != nil {- fmt.Printf("failed to shutdown server, error: %v\n", err)+ slog.Error("failed to shutdown server", slog.String("error", err.Error()))}// Close database connection.if err := s.Store.Close(); err != nil {- fmt.Printf("failed to close database, error: %v\n", err)+ slog.Error("failed to close database", slog.String("error", err.Error()))}- fmt.Printf("memos stopped properly\n")+ slog.Info("memos stopped properly")}func (s *Server) StartBackgroundRunners(ctx context.Context) {diff --git a/store/migrator.go b/store/migrator.goindex 05ee466ad..166261fa4 100644--- a/store/migrator.go+++ b/store/migrator.go@@ -72,7 +72,7 @@ func (s *Store) Migrate(ctx context.Context) error {}defer tx.Rollback()- fmt.Println("start migration")+ slog.Info("start migration", slog.String("currentSchemaVersion", latestMigrationHistoryVersion), slog.String("targetSchemaVersion", schemaVersion))for _, filePath := range filePaths {fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath)if err != nil {@@ -93,7 +93,7 @@ func (s *Store) Migrate(ctx context.Context) error {if err := tx.Commit(); err != nil {return errors.Wrap(err, "failed to commit transaction")}- fmt.Println("end migrate")+ slog.Info("end migrate")// Upsert the current schema version to migration_history.if _, err = s.driver.UpsertMigrationHistory(ctx, &UpsertMigrationHistory{@@ -255,6 +255,7 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {sort.Sort(version.SortVersion(versions))latestVersion := versions[len(versions)-1]latestMinorVersion := version.GetMinorVersion(latestVersion)+// If the latest version is greater than 0.22, return.// As of 0.22, the migration history is already normalized.if version.IsVersionGreaterThan(latestMinorVersion, "0.22") {diff --git a/test/store/store.go b/test/store/store.goindex 12ac92639..c1cf3a530 100644--- a/test/store/store.go+++ b/test/store/store.go@@ -2,7 +2,7 @@ package teststoreimport ("context"- "fmt"+ "log/slog""testing"// sqlite driver.@@ -18,13 +18,13 @@ func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {profile := test.GetTestingProfile(t)dbDriver, err := db.NewDBDriver(profile)if err != nil {- fmt.Printf("failed to create db driver, error: %+v\n", err)+ slog.Error("failed to create db driver", slog.String("error", err.Error()))}resetTestingDB(ctx, profile, dbDriver)store := store.New(dbDriver, profile)if err := store.Migrate(ctx); err != nil {- fmt.Printf("failed to migrate db, error: %+v\n", err)+ slog.Error("failed to migrate db", slog.String("error", err.Error()))}return store}@@ -48,7 +48,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver storDROP TABLE IF EXISTS webhook;DROP TABLE IF EXISTS reaction;`)if err != nil {- fmt.Printf("failed to reset testing db, error: %+v\n", err)+ slog.Error("failed to reset testing db", slog.String("error", err.Error()))panic(err)}} else if profile.Driver == "postgres" {@@ -69,7 +69,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver storDROP TABLE IF EXISTS webhook CASCADE;DROP TABLE IF EXISTS reaction CASCADE;`)if err != nil {- fmt.Printf("failed to reset testing db, error: %+v\n", err)+ slog.Error("failed to reset testing db", slog.String("error", err.Error()))panic(err)}}