add logger
This commit is contained in:
parent
fda22acffe
commit
a5f4d48aad
5 changed files with 88 additions and 0 deletions
|
|
@ -14,15 +14,21 @@ import (
|
|||
"recipe-manager/data"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/routers"
|
||||
"recipe-manager/services/logger"
|
||||
"recipe-manager/services/oauth"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var (
|
||||
Log = logger.GetInstance()
|
||||
)
|
||||
|
||||
func loadConfig(path string) (*config.ServerConfig, error) {
|
||||
viper.AddConfigPath(path)
|
||||
viper.SetConfigName("app")
|
||||
|
|
@ -69,8 +75,12 @@ func NewServer() *Server {
|
|||
|
||||
func (s *Server) Run() error {
|
||||
|
||||
// logger
|
||||
// defer log_inst.Sync()
|
||||
|
||||
s.createHandler()
|
||||
log.Printf("Server running on %s", s.server.Addr)
|
||||
Log.Info("Server running", zap.String("addr", s.server.Addr))
|
||||
return s.server.ListenAndServe()
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +134,9 @@ func (s *Server) createHandler() {
|
|||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "user", user)
|
||||
|
||||
Log.Info("User is authenticated", zap.String("user", user.Name))
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue