mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: tweak logger
This commit is contained in:
@@ -2,6 +2,7 @@ package profile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -68,7 +69,7 @@ func (p *Profile) Validate() error {
|
|||||||
p.Data = filepath.Join(os.Getenv("ProgramData"), "memos")
|
p.Data = filepath.Join(os.Getenv("ProgramData"), "memos")
|
||||||
if _, err := os.Stat(p.Data); os.IsNotExist(err) {
|
if _, err := os.Stat(p.Data); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(p.Data, 0770); err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ func (p *Profile) Validate() error {
|
|||||||
|
|
||||||
dataDir, err := checkDataDir(p.Data)
|
dataDir, err := checkDataDir(p.Data)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,11 +5,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/exp/slog"
|
||||||
|
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/server/profile"
|
||||||
@@ -115,7 +115,7 @@ func (r *Runner) Check(ctx context.Context) {
|
|||||||
ActivityId: &activity.ID,
|
ActivityId: &activity.ID,
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
fmt.Printf("failed to create inbox: %s\n", err)
|
slog.Error("failed to create inbox", slog.String("error", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -129,15 +129,15 @@ func (s *Server) Shutdown(ctx context.Context) {
|
|||||||
|
|
||||||
// Shutdown echo server.
|
// Shutdown echo server.
|
||||||
if err := s.echoServer.Shutdown(ctx); err != nil {
|
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.
|
// Close database connection.
|
||||||
if err := s.Store.Close(); err != nil {
|
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) {
|
func (s *Server) StartBackgroundRunners(ctx context.Context) {
|
||||||
|
@@ -72,7 +72,7 @@ func (s *Store) Migrate(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
fmt.Println("start migration")
|
slog.Info("start migration", slog.String("currentSchemaVersion", latestMigrationHistoryVersion), slog.String("targetSchemaVersion", schemaVersion))
|
||||||
for _, filePath := range filePaths {
|
for _, filePath := range filePaths {
|
||||||
fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath)
|
fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,7 +93,7 @@ func (s *Store) Migrate(ctx context.Context) error {
|
|||||||
if err := tx.Commit(); err != nil {
|
if err := tx.Commit(); err != nil {
|
||||||
return errors.Wrap(err, "failed to commit transaction")
|
return errors.Wrap(err, "failed to commit transaction")
|
||||||
}
|
}
|
||||||
fmt.Println("end migrate")
|
slog.Info("end migrate")
|
||||||
|
|
||||||
// Upsert the current schema version to migration_history.
|
// Upsert the current schema version to migration_history.
|
||||||
if _, err = s.driver.UpsertMigrationHistory(ctx, &UpsertMigrationHistory{
|
if _, err = s.driver.UpsertMigrationHistory(ctx, &UpsertMigrationHistory{
|
||||||
@@ -255,6 +255,7 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {
|
|||||||
sort.Sort(version.SortVersion(versions))
|
sort.Sort(version.SortVersion(versions))
|
||||||
latestVersion := versions[len(versions)-1]
|
latestVersion := versions[len(versions)-1]
|
||||||
latestMinorVersion := version.GetMinorVersion(latestVersion)
|
latestMinorVersion := version.GetMinorVersion(latestVersion)
|
||||||
|
|
||||||
// If the latest version is greater than 0.22, return.
|
// If the latest version is greater than 0.22, return.
|
||||||
// As of 0.22, the migration history is already normalized.
|
// As of 0.22, the migration history is already normalized.
|
||||||
if version.IsVersionGreaterThan(latestMinorVersion, "0.22") {
|
if version.IsVersionGreaterThan(latestMinorVersion, "0.22") {
|
||||||
|
@@ -2,7 +2,7 @@ package teststore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"log/slog"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
// sqlite driver.
|
// sqlite driver.
|
||||||
@@ -18,13 +18,13 @@ func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
|
|||||||
profile := test.GetTestingProfile(t)
|
profile := test.GetTestingProfile(t)
|
||||||
dbDriver, err := db.NewDBDriver(profile)
|
dbDriver, err := db.NewDBDriver(profile)
|
||||||
if err != nil {
|
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)
|
resetTestingDB(ctx, profile, dbDriver)
|
||||||
|
|
||||||
store := store.New(dbDriver, profile)
|
store := store.New(dbDriver, profile)
|
||||||
if err := store.Migrate(ctx); err != nil {
|
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
|
return store
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
|
|||||||
DROP TABLE IF EXISTS webhook;
|
DROP TABLE IF EXISTS webhook;
|
||||||
DROP TABLE IF EXISTS reaction;`)
|
DROP TABLE IF EXISTS reaction;`)
|
||||||
if err != nil {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
} else if profile.Driver == "postgres" {
|
} else if profile.Driver == "postgres" {
|
||||||
@@ -69,7 +69,7 @@ func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver stor
|
|||||||
DROP TABLE IF EXISTS webhook CASCADE;
|
DROP TABLE IF EXISTS webhook CASCADE;
|
||||||
DROP TABLE IF EXISTS reaction CASCADE;`)
|
DROP TABLE IF EXISTS reaction CASCADE;`)
|
||||||
if err != nil {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user