master
Evan Chen 2021-12-21 01:07:33 +08:00
parent 1a6235741b
commit 601e596980
2 changed files with 9 additions and 4 deletions

View File

@ -6,13 +6,17 @@ import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"kumoly.io/kumoly/app/history"
"kumoly.io/kumoly/app/system"
"kumoly.io/kumoly/app/util"
)
type SkipLogFunc func(c *gin.Context) bool
var l zerolog.Logger
type Service struct {
Name string
Server *gin.Engine
@ -51,19 +55,20 @@ func New(name string) *Service {
return srv
}
func (srv *Service) Init() error {
srv.l = util.Klog.With().Str("service", "server.Service").Str("name", srv.Name).Logger()
l = util.Klog.With().Str("service", "server.Service").Str("name", srv.Name).Logger()
srv.l = system.SetupLogger(log.Logger, 2)
return nil
}
func (srv *Service) Load() error {
return nil
}
func (srv *Service) Main() error {
srv.l.Info().Msgf("Server started on %s", srv.Addr)
l.Info().Msgf("Server started on %s", srv.Addr)
go func() {
err := srv.Server.Run(srv.Addr)
if err != nil {
history.Send(history.Error().Nm("ServerStartError").Msg(err.Error()))
srv.l.Panic().Err(err).Msg("Server.Run error")
l.Panic().Err(err).Msg("Server.Run error")
}
}()
return nil

View File

@ -48,7 +48,7 @@ func init() {
var setupped bool = false
func SetupLogger(l zerolog.Logger, skip ...int) zerolog.Logger {
if !util.PROD && len(skip) > 0 {
if !util.PROD && len(skip) == 0 {
l = l.With().Caller().Logger()
}
if viper.GetBool("log.pretty") {