chore: update logger

This commit is contained in:
Steven 2022-08-19 00:45:02 +08:00
parent ce390f3f79
commit e3fac742c5
2 changed files with 9 additions and 14 deletions

View file

@ -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)
}

View file

@ -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())