mirror of
https://github.com/usememos/memos.git
synced 2024-11-10 17:02:21 +08:00
chore: update logger
This commit is contained in:
parent
ce390f3f79
commit
e3fac742c5
2 changed files with 9 additions and 14 deletions
|
@ -22,34 +22,27 @@ const (
|
|||
`
|
||||
)
|
||||
|
||||
type Main struct {
|
||||
profile *profile.Profile
|
||||
}
|
||||
|
||||
func (m *Main) Run() error {
|
||||
func Run(profile *profile.Profile) error {
|
||||
ctx := context.Background()
|
||||
|
||||
db := DB.NewDB(m.profile)
|
||||
db := DB.NewDB(profile)
|
||||
if err := db.Open(ctx); err != nil {
|
||||
return fmt.Errorf("cannot open db: %w", err)
|
||||
}
|
||||
|
||||
s := server.NewServer(m.profile)
|
||||
s := server.NewServer(profile)
|
||||
|
||||
storeInstance := store.New(db.Db, m.profile)
|
||||
storeInstance := store.New(db.Db, profile)
|
||||
s.Store = storeInstance
|
||||
|
||||
println(greetingBanner)
|
||||
fmt.Printf("Version %s has started at :%d\n", m.profile.Version, m.profile.Port)
|
||||
fmt.Printf("Version %s has started at :%d\n", profile.Version, profile.Port)
|
||||
|
||||
return s.Run()
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
profile := profile.GetProfile()
|
||||
m := Main{
|
||||
profile: profile,
|
||||
}
|
||||
|
||||
println("---")
|
||||
println("profile")
|
||||
|
@ -59,7 +52,7 @@ func Execute() {
|
|||
println("version:", profile.Version)
|
||||
println("---")
|
||||
|
||||
if err := m.Run(); err != nil {
|
||||
if err := Run(profile); err != nil {
|
||||
fmt.Printf("error: %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ func NewServer(profile *profile.Profile) *Server {
|
|||
e.HidePort = true
|
||||
|
||||
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
||||
Format: "${method} ${uri} ${status}\n",
|
||||
Format: `{"time":"${time_rfc3339}",` +
|
||||
`"method":"${method}","uri":"${uri}",` +
|
||||
`"status":${status},"error":"${error}"}` + "\n",
|
||||
}))
|
||||
|
||||
e.Use(middleware.CORS())
|
||||
|
|
Loading…
Reference in a new issue