chore: update logger

This commit is contained in:
Steven
2024-02-29 23:54:43 +08:00
parent 12f4d3a10d
commit dfa78cac49
14 changed files with 87 additions and 146 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pkg/errors"
"github.com/usememos/memos/plugin/telegram"
@ -49,31 +48,15 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
telegramBot: telegram.NewBotWithHandler(integration.NewTelegramHandler(store)),
}
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: `{"time":"${time_rfc3339}","latency":"${latency_human}",` +
`"method":"${method}","uri":"${uri}",` +
`"status":${status},"error":"${error}"}` + "\n",
}))
// Register CORS middleware.
e.Use(CORSMiddleware())
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
Skipper: grpcRequestSkipper,
Timeout: 30 * time.Second,
}))
serverID, err := s.getSystemServerID(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to retrieve system server ID")
}
s.ID = serverID
// Only serve frontend when it's enabled.
if profile.Frontend {
frontendService := frontend.NewFrontendService(profile, store)
frontendService.Serve(ctx, e)
}
secret := "usememos"
if profile.Mode == "prod" {
secret, err = s.getSystemSecretSessionName(ctx)
@ -88,6 +71,12 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
return c.String(http.StatusOK, "Service ready.")
})
// Only serve frontend when it's enabled.
if profile.Frontend {
frontendService := frontend.NewFrontendService(profile, store)
frontendService.Serve(ctx, e)
}
// Register API v1 endpoints.
rootGroup := e.Group("")
apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, s.telegramBot)