Add default name to logger
This commit is contained in:
parent
bba66fe4cc
commit
1cfae5917e
16
server.go
16
server.go
|
@ -23,6 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
log log.Logger
|
||||||
address string
|
address string
|
||||||
theme string
|
theme string
|
||||||
debug bool
|
debug bool
|
||||||
|
@ -211,7 +212,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem
|
||||||
if strings.Contains(path, ".html") {
|
if strings.Contains(path, ".html") {
|
||||||
_, err := s.parseTemplates(tmpl, path)
|
_, err := s.parseTemplates(tmpl, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v\n", err)
|
s.log.Printf("%+v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -227,7 +228,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem
|
||||||
func (s *Server) loadTemplates() *template.Template {
|
func (s *Server) loadTemplates() *template.Template {
|
||||||
tmpl, err := s.LoadTemplatesFS(s.fs, s.templates)
|
tmpl, err := s.LoadTemplatesFS(s.fs, s.templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("loadTemplates %v %v\n", err, s.templates)
|
s.log.Fatalf("loadTemplates %v %v\n", err, s.templates)
|
||||||
}
|
}
|
||||||
return tmpl
|
return tmpl
|
||||||
}
|
}
|
||||||
|
@ -254,7 +255,7 @@ func (s *Server) render(w http.ResponseWriter, tmpl string, content interface{})
|
||||||
}
|
}
|
||||||
err := s.getTemplates().ExecuteTemplate(w, tmpl, content)
|
err := s.getTemplates().ExecuteTemplate(w, tmpl, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("%s\n", err)
|
s.log.Warnf("%s\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +285,7 @@ func (s *Server) HandleFuncAuthenticatedWithLogin(path string, loginHandler func
|
||||||
|
|
||||||
func (s *Server) HandleFuncCustomAuth(auth auth.Authenticator, path, redirect string, f func(c *Context)) *mux.Route {
|
func (s *Server) HandleFuncCustomAuth(auth auth.Authenticator, path, redirect string, f func(c *Context)) *mux.Route {
|
||||||
if auth == nil {
|
if auth == nil {
|
||||||
log.Warnf("Nil auth on %s\n", path)
|
s.log.Warnf("Nil auth on %s\n", path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return s.router.HandleFunc(path, s.authenticated(auth, redirect, f))
|
return s.router.HandleFunc(path, s.authenticated(auth, redirect, f))
|
||||||
|
@ -320,7 +321,7 @@ func (s *Server) Router() *mux.Router {
|
||||||
func (s *Server) ServeTLS(keyPath string, certPath string) error {
|
func (s *Server) ServeTLS(keyPath string, certPath string) error {
|
||||||
kpr, err := autocert.NewManager(certPath, keyPath)
|
kpr, err := autocert.NewManager(certPath, keyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v\n", err)
|
s.log.Fatalf("%v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.http = &http.Server{
|
s.http = &http.Server{
|
||||||
|
@ -422,6 +423,10 @@ func (s *Server) WithHealthCheck(version, date string, status func() (bool, stri
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) SetLogger(logger log.Logger) {
|
||||||
|
s.log = logger
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) Dump() {
|
func (s *Server) Dump() {
|
||||||
fmt.Printf(" Theme: %s\n", s.theme)
|
fmt.Printf(" Theme: %s\n", s.theme)
|
||||||
fmt.Printf(" Templates: %s\n", s.templates)
|
fmt.Printf(" Templates: %s\n", s.templates)
|
||||||
|
@ -443,6 +448,7 @@ func New(address string, path string, auth auth.Authenticator) *Server {
|
||||||
templateFuncs: builtinFuncMap,
|
templateFuncs: builtinFuncMap,
|
||||||
theme: "/static/css/default.css",
|
theme: "/static/css/default.css",
|
||||||
meta: make(map[string]string),
|
meta: make(map[string]string),
|
||||||
|
log: log.WithName("SNAP"),
|
||||||
}
|
}
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue